PyWart: "Python's import statement and the history of external dependencies"

Tim Chase python.list at tim.thechases.com
Fri Nov 21 05:26:27 EST 2014


On 2014-11-20 19:53, Rick Johnson wrote:
> FOR INSTANCE: Let's say i write a module that presents a
> reusable GUI calendar widget, and then i name the module
> "calender.py".
> 
> Then Later, when i try to import *MY* GUI widget named
> "calendar", i will not get *MY* calendar widget, no, i will
> get the Python calendar module.
> 
> The reason Python finds the library module instead of my
> module is because the Python library is higher in search
> path than my module.

What messed-up version of Python are you running?  Or did you fail to
test your conjecture?

$ cat > calendar.py
print("This is my local calendar.py")
x=1
$ cat > importtest.py
import calendar
print(dir(calendar))
$ python2 importtest.py 
This is my local calendar.py
['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'x']
$ python3 importtest.py
This is my local calendar.py
['__builtins__', '__cached__', '__doc__', '__file__', '__name__', '__package__', 'x']


It finds my local module, not the system "calendar" module.

-tkc









More information about the Python-list mailing list