From 593801142edc7c2c9e8ba214cb88a0a1878b50a9 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Sun, 7 Sep 1997 02:56:35 +0000 Subject: Initial revision --- Doc/lib/libni.tex | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ Doc/libni.tex | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 Doc/lib/libni.tex create mode 100644 Doc/libni.tex diff --git a/Doc/lib/libni.tex b/Doc/lib/libni.tex new file mode 100644 index 0000000..b0f07a8 --- /dev/null +++ b/Doc/lib/libni.tex @@ -0,0 +1,49 @@ +\section{Built-in Module \sectcode{ni}} +\label{module-ni} +\bimodindex{ni} + +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: + +\bcode\begin{verbatim} +import spam.ham # *not* "import spam" !!! +spam.ham.hamneggs() +\end{verbatim}\ecode +% +\bcode\begin{verbatim} +from spam import ham +ham.hamneggs() +\end{verbatim}\ecode +% +\bcode\begin{verbatim} +from spam.ham import hamneggs +hamneggs() +\end{verbatim}\ecode +% +\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): + +\bcode\begin{verbatim} +__.spam_inited = 1 # Set a package-level variable +\end{verbatim}\ecode +% +Additional initialization code (setting up variables, importing other +submodules) can be performed in \file{spam/__init__.py}. diff --git a/Doc/libni.tex b/Doc/libni.tex new file mode 100644 index 0000000..b0f07a8 --- /dev/null +++ b/Doc/libni.tex @@ -0,0 +1,49 @@ +\section{Built-in Module \sectcode{ni}} +\label{module-ni} +\bimodindex{ni} + +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: + +\bcode\begin{verbatim} +import spam.ham # *not* "import spam" !!! +spam.ham.hamneggs() +\end{verbatim}\ecode +% +\bcode\begin{verbatim} +from spam import ham +ham.hamneggs() +\end{verbatim}\ecode +% +\bcode\begin{verbatim} +from spam.ham import hamneggs +hamneggs() +\end{verbatim}\ecode +% +\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): + +\bcode\begin{verbatim} +__.spam_inited = 1 # Set a package-level variable +\end{verbatim}\ecode +% +Additional initialization code (setting up variables, importing other +submodules) can be performed in \file{spam/__init__.py}. -- cgit v0.12