[Python-bugs-list] [Bug #115528] import creates extra modules if in working directory

noreply@sourceforge.net noreply@sourceforge.net
Thu, 28 Sep 2000 06:18:24 -0700

Bug #115528, was updated on 2000-Sep-27 20:08
Here is a current snapshot of the bug.

Project: Python
Category: Core
Status: Open
Resolution: None
Bug Group: None
Priority: 5
Summary: import creates extra modules if in working directory

Details: Given the directory structure:


and PYTHONPATH includes lib

If my current working directory is lib/foo, then
>>> import bar
>>> print bar.__file__
>>> import foo.bar
>>> print foo.bar.__file__
>>> print bar == foo.bar

I think that any one file should produce only one module at runtime and this behavior is wrong.

The reason I am trying to count on file-module mapping is because I was to index some behavior by class, and if I can't count on classes from the same file testing identical then I'm stuck.


Date: 2000-Sep-28 06:15
By: fdrake

This is a result of including both lib/ and . (as '') on sys.path; the file is legitimately found for two different module imports, so it is loaded for each.  We recommend that you do not run the Python interpreter from within a package; determining this situation from the interpreter at runtime would be prohibitively expensive and slow startup.

Date: 2000-Sep-28 06:18
By: lemburg

Perhaps modules should use an absolute file name in the __file__
attribute and also be stored under this name in the module
dictionary ?!

For detailed info, follow this link: