blob: fa2b3eebf44e28a4d3177fdf0a004a7124d1790e [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{ni} ---
2 None}
Fred Drakeb91e9341998-07-23 17:59:49 +00003\declaremodule{standard}{ni}
4
5\modulesynopsis{None}
6
Guido van Rossum59380111997-09-07 02:56:35 +00007
Guido van Rossum16221121997-09-07 03:02:39 +00008\strong{Warning: This module is obsolete.} As of Python 1.5a4,
9package support (with different semantics for \code{__init__} and no
Guido van Rossum138dac51997-12-09 15:03:41 +000010support for \code{__domain__} or \code{__}) is built in the
Guido van Rossum16221121997-09-07 03:02:39 +000011interpreter. The ni module is retained only for backward
Guido van Rossum138dac51997-12-09 15:03:41 +000012compatibility. As of Python 1.5b2, it has been renamed to \code{ni1};
13if you really need it, you can use \code{import ni1}, but the
14recommended approach is to rely on the built-in package support,
15converting existing packages if needed. Note that mixing \code{ni}
Fred Drake0cf785a1998-01-09 22:37:52 +000016and the built-in package support doesn't work: once you import
Guido van Rossum138dac51997-12-09 15:03:41 +000017\code{ni}, all packages use it.
Guido van Rossum16221121997-09-07 03:02:39 +000018
Guido van Rossum59380111997-09-07 02:56:35 +000019The \code{ni} module defines a new importing scheme, which supports
20packages containing several Python modules. To enable package
21support, execute \code{import ni} before importing any packages. Importing
22this module automatically installs the relevant import hooks. There
23are no publicly-usable functions or variables in the \code{ni} module.
24
25To 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
27path, 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
30To import module \code{ham} from package \code{spam} and use function
31\code{hamneggs()} from that module, you can use any of the following
32possibilities:
33
Fred Drake19479911998-02-13 06:58:54 +000034\begin{verbatim}
Guido van Rossum59380111997-09-07 02:56:35 +000035import spam.ham # *not* "import spam" !!!
36spam.ham.hamneggs()
Fred Drake19479911998-02-13 06:58:54 +000037\end{verbatim}
Guido van Rossum59380111997-09-07 02:56:35 +000038%
Fred Drake19479911998-02-13 06:58:54 +000039\begin{verbatim}
Guido van Rossum59380111997-09-07 02:56:35 +000040from spam import ham
41ham.hamneggs()
Fred Drake19479911998-02-13 06:58:54 +000042\end{verbatim}
Guido van Rossum59380111997-09-07 02:56:35 +000043%
Fred Drake19479911998-02-13 06:58:54 +000044\begin{verbatim}
Guido van Rossum59380111997-09-07 02:56:35 +000045from spam.ham import hamneggs
46hamneggs()
Fred Drake19479911998-02-13 06:58:54 +000047\end{verbatim}
Guido van Rossum59380111997-09-07 02:56:35 +000048%
49\code{import spam} creates an
50empty package named \code{spam} if one does not already exist, but it does
51\emph{not} automatically import \code{spam}'s submodules.
52The 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
56spam's namespace as \code{__} (two underscores):
57
Fred Drake19479911998-02-13 06:58:54 +000058\begin{verbatim}
Guido van Rossum59380111997-09-07 02:56:35 +000059__.spam_inited = 1 # Set a package-level variable
Fred Drake19479911998-02-13 06:58:54 +000060\end{verbatim}
Guido van Rossum59380111997-09-07 02:56:35 +000061%
62Additional initialization code (setting up variables, importing other
63submodules) can be performed in \file{spam/__init__.py}.