Parent module idea dropped? [WAS: import statement - package visibility problem]

Laszlo Zsolt Nagy gandalf at geochemsource.com
Fri Apr 8 02:47:26 EDT 2005


>But onto the point you're making. I think its possibly a mis-viewing
>of the package idea in Python. A package creates a name space. If you
>create Lib/Server/Db with all the __init__.py files, its because you
>want to import Lib.Server.Db,  rather than a way of organising your
>source files.
>  
>
I went forward. I read all the documentation in the language reference.

About the import statement:

http://docs.python.org/ref/import.html

For importing packages and using hierarchical module names, there was no 
detailed description but a link to an essay:

http://www.python.org/doc/essays/packages.html

There is a section in that essay named "Intra-package references". It says:

"""The submodules often need to refer to each other. For example, the 
surround module might use the echo module. In fact, such references are 
so common that the import statement first looks in the containing 
package before looking in the standard module search path. Thus, the 
surround module can simply use |import echo| or |from echo import 
echofilter|. If the imported module is not found in the current package 
(the package of which the current module is a submodule), the import 
statement looks for a top-level module with the given name.

When packages are structured into subpackage (as with the Sound package 
in the example), there's no shortcut to refer to submodules of sibling 
packages - the full name of the subpackage must be used. For example, if 
the module Sound.Filters.vocoder needs to use the echo module in the 
Sound.Effects package, it can use |from Sound.Effects import echo|.

(One could design a notation to refer to parent packages, similar to the 
use of ".." to refer to the parent directory in Unix and Windows 
filesystems. In fact, ni supported this using __ for the package 
containing the current module, __.__ for the parent package, and so on. 
This feature was dropped because of its awkwardness; since most packages 
will have a relative shallow substructure, this is no big loss.)
"""

So finally I got the answer: there was a "parent package" feature in the 
ni module but it was dropped of its awkwardness. This is not a big loss 
but this is exatly the feature that I need. Is there a person on this 
list who was against the "parent package" idea? He must know the answer 
or a workaround :-)

-- 

_________________________________________________________________
  Laszlo Nagy		      web: http://designasign.biz
  IT Consultant		      mail: gandalf at geochemsource.com

     		Python forever!





More information about the Python-list mailing list