Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 507f15b

Browse files
committed
Auto-install on first import.
Added quick reference.
1 parent ddcb36b commit 507f15b

2 files changed

Lines changed: 90 additions & 0 deletions

File tree

Lib/ni.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,48 @@
11
"""New import scheme with package support.
22
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+
346
A Package is a module that can contain other modules. Packages can be
447
nested. Package introduce dotted names for modules, like P.Q.M, which
548
could correspond to a file P/Q/M.py found somewhere on sys.path. It
@@ -388,3 +431,5 @@ def testproper():
388431

389432
if __name__ == '__main__':
390433
test()
434+
else:
435+
install()

Lib/ni1.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,48 @@
11
"""New import scheme with package support.
22
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+
346
A Package is a module that can contain other modules. Packages can be
447
nested. Package introduce dotted names for modules, like P.Q.M, which
548
could correspond to a file P/Q/M.py found somewhere on sys.path. It
@@ -388,3 +431,5 @@ def testproper():
388431

389432
if __name__ == '__main__':
390433
test()
434+
else:
435+
install()

0 commit comments

Comments
 (0)