(Serious?) package namespace problem (and a proposal)
Huaiyu Zhu
hzhu at knowledgetrack.com
Wed Jun 28 20:24:36 EDT 2000
More information about the Python-list mailing list
Wed Jun 28 20:24:36 EDT 2000
- Previous message (by thread): (Serious?) package namespace problem (and a proposal)
- Next message (by thread): (Serious?) package namespace problem (and a proposal)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 29 Jun 2000 01:56:19 +0200, Bernhard Herzog <herzog at online.de> wrote: > >If your cwd is python then the sys.path entry for python/ and '.' are >the same directory. Why would that lead to problems? The only thing I >can think of is that other directories in sys.path also have AAA >modules. Sorry I completely messed up my description. (And apologies for complaining about earlier correspondents not seeing the problem.) Here's a retake: $PYTHONPATH/ AAA/ __init__.py BBB/ __init__.py aaa.py ccc.py CCC/ ... Within BBB/aaa.py the statement 'import AAA' imports from AAA/__init__.py on Unix but from BBB/aaa.py on Windows. The reason is that within the BBB package python first looks for a module called AAA within the package (which it found as aaa.py on Windows) before it looks for a package named AAA. Although this is often the desired behavior, the other way around is also fairly common. In my case AAA and CCC are packages written by others and BBB is a wraper pacakge that imports the other packages to do the real work but provides different interfaces for convenience. Using identical names seems very natural here. Since there is no way to tell python to go to absolute path first, one has to make all module names in all packages distinct. This IMHO defeats one of the most important purpose of using packages, that is to encapsulate name spaces for module names. Therefore I think it is desirable for python to provide a mechanism for programmers to describe absolute path of imports. Like on Unix, writing /bin/sh in stead of sh in a script will guarantee its behavior no matter where it is run and what the current PATH the user has. My previous proposal was to use import pythonroot.AAA but in analogy with Unix paths maybe a syntax like import .AAA is even better. (BTW, this is the scheme used in DNS configurations for distinguishing qualified and unqualified domain names.) -- Huaiyu Zhu hzhu at users.sourceforge.net Matrix for Python Project http://MatPy.sourceforge.net
- Previous message (by thread): (Serious?) package namespace problem (and a proposal)
- Next message (by thread): (Serious?) package namespace problem (and a proposal)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list