2006/12/4, Graham Dumpleton <[EMAIL PROTECTED]>:
Clodoaldo wrote ..
> 2006/12/3, Graham Dumpleton <[EMAIL PROTECTED]>:
> >
> > Can you and anyone else who is interested, read through the
> > documentation
> > I have added and comment on whether it is adequate. Ie., is there
> > anything
> > that you can think is missing based on your own knowledge of the new
> > importer,
> > or anything that is particularly clear.
> >
>
> This paragraph is not clear for me:
>
> "In this scheme for maintaining a pseudo package, individual modules
> are still placed into a directory, but there cannot be a __init__.py
> file in the directory. If such a file does exist, it will simply be
> ignored."
>
> It says there cannot be a __init__.py file in the directory and
> immediately after it says that if it exists it will be ignored. What
> will be ignored? The file or the pseudo package?
>
> Thinking about it the only way that the paragraph makes sense is if
> the package is ignored but for me it is confusing at first sight.
Does this make more sense?
Although true Python packages are not candidates for reloading and must
be located in a directory listed in \code{sys.path}, another form of
packaging up modules such that they can be maintained within their own
namespace is supported. When this mechanism is used, these modules will
be candidates for reloading when found by the mod_python module importer.
In this scheme for maintaining a pseudo package, individual modules are
still placed into a directory, but the \code{__init__.py} file in the
directory has no special meaning and will not be automatically imported
as is the case with true Python packages. Instead, any module within the
directory must always be explicitly identified when performing an import.
To import a named module contained within these pseudo package, rather
than using a '.' to distinguish a sub module from the parent, a '/' is
used instead. For example:
\begin{verbatim}
from mod_python import apache
module = apache.import_module('dirname/module_name')
\end{verbatim}
If an \code{__init__.py} file is present and it was necessary to import
it to achieve the same result as importing the root of a true Python
package, then \code{__init__} can be used as the module name. For example:
\begin{verbatim}
from mod_python import apache
module = apache.import_module('dirname/__init__')
\end{verbatim}
As a true Python package is not being used, if a module in the directory
needs to refer to another module in the same directory, it should use
just its name, it should not use any form of dotted path name via the
root of the package as with true Python packages. Modules in
subdirectories can be imported by using a '/' separated path where the
first part of the path is the name of the subdirectory.
Graham
It is clear now for me.
--
Clodoaldo Pinto Neto