|
1 | 1 | """New import scheme with package support. |
2 | 2 |
|
| 3 | +Quick Reference |
| 4 | +--------------- |
| 5 | +
|
| 6 | +- To enable package support, execute "import ni" before importing any |
| 7 | + packages. Importing this module automatically installs the relevant |
| 8 | + import hooks. |
| 9 | +
|
| 10 | +- To create a package named spam containing sub-modules ham, bacon and |
| 11 | + eggs, create a directory spam somewhere on Python's module search |
| 12 | + path (i.e. spam's parent directory must be one of the directories in |
| 13 | + sys.path or $PYTHONPATH); then create files ham.py, bacon.py and |
| 14 | + eggs.py inside spam. |
| 15 | +
|
| 16 | +- To import module ham from package spam and use function hamneggs() |
| 17 | + from that module, you can either do |
| 18 | +
|
| 19 | + import spam.ham # *not* "import spam" !!! |
| 20 | + spam.ham.hamneggs() |
| 21 | +
|
| 22 | + or |
| 23 | +
|
| 24 | + from spam import ham |
| 25 | + ham.hamneggs() |
| 26 | +
|
| 27 | + or |
| 28 | +
|
| 29 | + from spam.ham import hamneggs |
| 30 | + hamneggs() |
| 31 | +
|
| 32 | +- Importing just "spam" does not do what you expect: it creates an |
| 33 | + empty package named spam if one does not already exist, but it does |
| 34 | + not import spam's submodules. The only submodule that is guaranteed |
| 35 | + to be imported is spam.__init__, if it exists. Note that |
| 36 | + spam.__init__ is a submodule of package spam. It can reference to |
| 37 | + spam's namespace via the '__.' prefix, for instance |
| 38 | +
|
| 39 | + __.spam_inited = 1 # Set a package-level variable |
| 40 | +
|
| 41 | +
|
| 42 | +
|
| 43 | +Theory of Operation |
| 44 | +------------------- |
| 45 | +
|
3 | 46 | A Package is a module that can contain other modules. Packages can be |
4 | 47 | nested. Package introduce dotted names for modules, like P.Q.M, which |
5 | 48 | could correspond to a file P/Q/M.py found somewhere on sys.path. It |
@@ -388,3 +431,5 @@ def testproper(): |
388 | 431 |
|
389 | 432 | if __name__ == '__main__': |
390 | 433 | test() |
| 434 | +else: |
| 435 | + install() |
0 commit comments