How to guard against bugs like this one?
invalid at invalid.invalid
Tue Feb 2 16:00:28 CET 2010
On 2010-02-02, Roy Smith <roy at panix.com> wrote:
> In article <hk82uv$8kn$1 at reader1.panix.com>, kj <no.email at please.post>
>> Through a *lot* of trial an error I finally discovered that the
>> root cause of the problem was the fact that, in the same directory
>> as buggy.py, there is *another* innocuous little script, totally
>> unrelated, whose name happens to be numbers.py.
>> It turns out that buggy.py imports psycopg2, as you can see, and
>> apparently psycopg2 (or something imported by psycopg2) tries to
>> import some standard Python module called numbers; instead it ends
>> up importing the innocent myscript/numbers.py, resulting in *absolute
> I feel your pain, but this is not a Python problem, per-se.
I think it is. There should be different syntax to import from
"standard" places and from "current directory". Similar to the
difference between "foo.h" and <foo.h> in cpp.
> The general
> pattern is:
> 1) You have something which refers to a resource by name.
> 2) There is a sequence of places which are searched for this
Searching the current directory by default is the problem.
Nobody in their right mind has "." in the shell PATH and IMO it
shouldn't be in Python's import path either. Even those
wreckless souls who do put "." in their path put it at the end
so they don't accidentally override system commands.
Grant Edwards grante Yow! So this is what it
at feels like to be potato
More information about the Python-list