diff options
author | cinap_lenrek <cinap_lenrek@localhost> | 2011-05-03 11:25:13 +0000 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@localhost> | 2011-05-03 11:25:13 +0000 |
commit | 458120dd40db6b4df55a4e96b650e16798ef06a0 (patch) | |
tree | 8f82685be24fef97e715c6f5ca4c68d34d5074ee /sys/src/cmd/python/Doc/lib/libni.tex | |
parent | 3a742c699f6806c1145aea5149bf15de15a0afd7 (diff) |
add hg and python
Diffstat (limited to 'sys/src/cmd/python/Doc/lib/libni.tex')
-rw-r--r-- | sys/src/cmd/python/Doc/lib/libni.tex | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/sys/src/cmd/python/Doc/lib/libni.tex b/sys/src/cmd/python/Doc/lib/libni.tex new file mode 100644 index 000000000..fa2b3eebf --- /dev/null +++ b/sys/src/cmd/python/Doc/lib/libni.tex @@ -0,0 +1,63 @@ +\section{\module{ni} --- + None} +\declaremodule{standard}{ni} + +\modulesynopsis{None} + + +\strong{Warning: This module is obsolete.} As of Python 1.5a4, +package support (with different semantics for \code{__init__} and no +support for \code{__domain__} or \code{__}) is built in the +interpreter. The ni module is retained only for backward +compatibility. As of Python 1.5b2, it has been renamed to \code{ni1}; +if you really need it, you can use \code{import ni1}, but the +recommended approach is to rely on the built-in package support, +converting existing packages if needed. Note that mixing \code{ni} +and the built-in package support doesn't work: once you import +\code{ni}, all packages use it. + +The \code{ni} module defines a new importing scheme, which supports +packages containing several Python modules. To enable package +support, execute \code{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 \code{ni} module. + +To create a package named \code{spam} containing sub-modules \code{ham}, \code{bacon} and +\code{eggs}, create a directory \file{spam} somewhere on Python's module search +path, as given in \code{sys.path}. Then, create files called \file{ham.py}, \file{bacon.py} and +\file{eggs.py} inside \file{spam}. + +To import module \code{ham} from package \code{spam} and use function +\code{hamneggs()} from that module, you can use any of the following +possibilities: + +\begin{verbatim} +import spam.ham # *not* "import spam" !!! +spam.ham.hamneggs() +\end{verbatim} +% +\begin{verbatim} +from spam import ham +ham.hamneggs() +\end{verbatim} +% +\begin{verbatim} +from spam.ham import hamneggs +hamneggs() +\end{verbatim} +% +\code{import spam} creates an +empty package named \code{spam} if one does not already exist, but it does +\emph{not} automatically import \code{spam}'s submodules. +The only submodule that is guaranteed to be imported is +\code{spam.__init__}, if it exists; it would be in a file named +\file{__init__.py} in the \file{spam} directory. Note that +\code{spam.__init__} is a submodule of package spam. It can refer to +spam's namespace as \code{__} (two underscores): + +\begin{verbatim} +__.spam_inited = 1 # Set a package-level variable +\end{verbatim} +% +Additional initialization code (setting up variables, importing other +submodules) can be performed in \file{spam/__init__.py}. |