Hi There is a subtle bug in the import structure of scipy which nearly drove me crazy. Here is how to reproduce it: ==== import scipy ==== imports and executes any file named "new.py" in the current working directory. Python 2.3.3 (#1, Apr 6 2004, 01:47:39) [GCC 3.3.3 (SuSE Linux)] on linux2 scipy.__version__ '0.3.1_285.4270' Thanks, Martin -- Martin L�thi answer@tnoo.net
Martin Lüthi wrote:
Hi
There is a subtle bug in the import structure of scipy which nearly drove me crazy.
Here is how to reproduce it:
==== import scipy ====
imports and executes any file named "new.py" in the current working directory.
Python 2.3.3 (#1, Apr 6 2004, 01:47:39) [GCC 3.3.3 (SuSE Linux)] on linux2
scipy.__version__ '0.3.1_285.4270'
I think this 'bug' will happen anytime you name a file using a Python module name that another module is expecting. Your new.py file is over-riding the Python module new here that parts of scipy depends on. Try naming a file re.py in your current directory and you will get similar problems. -Travis
Hi Travis Thanks for your explanation. Travis Oliphant <oliphant@ee.byu.edu> writes:
==== import scipy ====
imports and executes any file named "new.py" in the current working
I think this 'bug' will happen anytime you name a file using a Python module name that another module is expecting. Your new.py file is over-riding the Python module new here that parts of scipy depends on.
Try naming a file re.py in your current directory and you will get similar problems. -Travis
So whether a given library works depends on the file names that one has in a random directory. Hmmm. This is a nasty behavior, and I'm glad I never run this before. To me this looks like a design flaw if the module names from the standard library are not __somehow__ protected. I'll have to ponder about PYTHON_PATH, but this whole business seems to be quite fragile. As little as I like Java, the module naming scheme is the one thing that they got right. Time for a PEP? Best, Martin -- Martin L�thi answer@tnoo.net
Martin Lüthi schrieb:
So whether a given library works depends on the file names that one has in a random directory. Hmmm. This is a nasty behavior, and I'm glad I never run this before. To me this looks like a design flaw if the module names from the standard library are not __somehow__ protected.
I'll have to ponder about PYTHON_PATH, but this whole business seems to be quite fragile. As little as I like Java, the module naming scheme is the one thing that they got right. Time for a PEP?
Don't bother. As of python 2.4 (or is it 2.5?, I don't recall), imports will require an absolute path, so this problem should be much less common. http://www.python.org/peps/pep-0328.html Best, f
participants (3)
-
answer@tnoo.net -
Fernando Perez -
Travis Oliphant