The Zope Bible phần 4

bất kỳ thay đổi bạn thực hiện nên trở thành có thể nhìn thấy ngay lập tức. Lên trên Frame tùy chọn Hiển thị cũng yêu cầu bạn làm mới trình duyệt của bạn sau khi nhấp nút Change. Chương 10 ✦ Tạo một AddressBook Multi-User | Chapter 5 Object-Oriented Programming and Python 165 Now import the package using the same syntax that you used to import a module from helloproject import from hellocode import Traceback innermost last File interactive input line 0 in NameError hellocode Oops. As this demonstrates packages do not automatically import their contained files even when you use the from package import syntax. Because some file systems are case-sensitive and others are not you need to tell Python what names to expose to a request to get all importable objects. This is done by adding analllist into the_i file like so all hellocode goodbyecode Note that this is not entirely necessary. If you want to import objects more explicitly you can still do so without using_all_ from helloproject import hellocode Hello World And you can drill down with even more accuracy like this from import hello hello Hello World Tip You should use the_all__attribute in youri files when you intend the entire package to be imported using from package import . While it may seem reasonable to hide names form being imported by failing to include them in theall__list this is actually a bad idea. Instead names that need to remain private should begin with an underscore _ as was discussed earlier in this chapter. 166 Part I Getting Started with Zope Examining the contents of a namespace with dir Let s say you want to find out what names are defined in an imported module regardless of whether that module was in a package. You could examine the module s code directly but that can be tedious and repetitive. Aren t computers good at automating repetitive tasks Yes they are. from helloproject import hellocode dir hellocode __builtins__ __doc __file__ __name__ hello The dir function returns a list of all the names in the module. It s not limited to just modules either. For example you can get a list of everything in the current namespace by