1 | \section{\module{ni} ---
|
---|
2 | None}
|
---|
3 | \declaremodule{standard}{ni}
|
---|
4 |
|
---|
5 | \modulesynopsis{None}
|
---|
6 |
|
---|
7 |
|
---|
8 | \strong{Warning: This module is obsolete.} As of Python 1.5a4,
|
---|
9 | package support (with different semantics for \code{__init__} and no
|
---|
10 | support for \code{__domain__} or \code{__}) is built in the
|
---|
11 | interpreter. The ni module is retained only for backward
|
---|
12 | compatibility. As of Python 1.5b2, it has been renamed to \code{ni1};
|
---|
13 | if you really need it, you can use \code{import ni1}, but the
|
---|
14 | recommended approach is to rely on the built-in package support,
|
---|
15 | converting existing packages if needed. Note that mixing \code{ni}
|
---|
16 | and the built-in package support doesn't work: once you import
|
---|
17 | \code{ni}, all packages use it.
|
---|
18 |
|
---|
19 | The \code{ni} module defines a new importing scheme, which supports
|
---|
20 | packages containing several Python modules. To enable package
|
---|
21 | support, execute \code{import ni} before importing any packages. Importing
|
---|
22 | this module automatically installs the relevant import hooks. There
|
---|
23 | are no publicly-usable functions or variables in the \code{ni} module.
|
---|
24 |
|
---|
25 | To create a package named \code{spam} containing sub-modules \code{ham}, \code{bacon} and
|
---|
26 | \code{eggs}, create a directory \file{spam} somewhere on Python's module search
|
---|
27 | path, as given in \code{sys.path}. Then, create files called \file{ham.py}, \file{bacon.py} and
|
---|
28 | \file{eggs.py} inside \file{spam}.
|
---|
29 |
|
---|
30 | To import module \code{ham} from package \code{spam} and use function
|
---|
31 | \code{hamneggs()} from that module, you can use any of the following
|
---|
32 | possibilities:
|
---|
33 |
|
---|
34 | \begin{verbatim}
|
---|
35 | import spam.ham # *not* "import spam" !!!
|
---|
36 | spam.ham.hamneggs()
|
---|
37 | \end{verbatim}
|
---|
38 | %
|
---|
39 | \begin{verbatim}
|
---|
40 | from spam import ham
|
---|
41 | ham.hamneggs()
|
---|
42 | \end{verbatim}
|
---|
43 | %
|
---|
44 | \begin{verbatim}
|
---|
45 | from spam.ham import hamneggs
|
---|
46 | hamneggs()
|
---|
47 | \end{verbatim}
|
---|
48 | %
|
---|
49 | \code{import spam} creates an
|
---|
50 | empty package named \code{spam} if one does not already exist, but it does
|
---|
51 | \emph{not} automatically import \code{spam}'s submodules.
|
---|
52 | The only submodule that is guaranteed to be imported is
|
---|
53 | \code{spam.__init__}, if it exists; it would be in a file named
|
---|
54 | \file{__init__.py} in the \file{spam} directory. Note that
|
---|
55 | \code{spam.__init__} is a submodule of package spam. It can refer to
|
---|
56 | spam's namespace as \code{__} (two underscores):
|
---|
57 |
|
---|
58 | \begin{verbatim}
|
---|
59 | __.spam_inited = 1 # Set a package-level variable
|
---|
60 | \end{verbatim}
|
---|
61 | %
|
---|
62 | Additional initialization code (setting up variables, importing other
|
---|
63 | submodules) can be performed in \file{spam/__init__.py}.
|
---|