ni
Warning: This module is obsolete. As of Python 1.5a4,
package support (with different semantics for __init__
and no
support for __domain__
or __
) is built in the
interpreter. The ni module is retained only for backward
compatibility. As of Python 1.5b2, it has been renamed to ni1
;
if you really need it, you can use import ni1
, but the
recommended approach is to rely on the built-in package support,
converting existing packages if needed. Note that mixing ni
and the built-in package support doesn't work once you import
ni
, all packages use it.
The ni
module defines a new importing scheme, which supports
packages containing several Python modules. To enable package
support, execute import ni
before importing any packages. Importing
this module automatically installs the relevant import hooks. There
are no publicly-usable functions or variables in the ni
module.
To create a package named spam
containing sub-modules ham
, bacon
and
eggs
, create a directory `spam
' somewhere on Python's module search
path, as given in sys.path
. Then, create files called `ham.py
', `bacon.py
' and
`eggs.py
' inside `spam
'.
To import module ham
from package spam
and use function
hamneggs()
from that module, you can use any of the following
possibilities:
import spam.ham # *not* "import spam" !!! spam.ham.hamneggs()
from spam import ham ham.hamneggs()
from spam.ham import hamneggs hamneggs()
import spam
creates an
empty package named spam
if one does not already exist, but it does
not automatically import spam
's submodules.
The only submodule that is guaranteed to be imported is
spam.__init__
, if it exists; it would be in a file named
`__init__.py
' in the `spam
' directory. Note that
spam.__init__
is a submodule of package spam. It can refer to
spam's namespace as __
(two underscores):
__.spam_inited = 1 # Set a package-level variableAdditional initialization code (setting up variables, importing other submodules) can be performed in `
spam/__init__.py
'.