[Tutor] question about sys.path and importing
Dick Moores
rdm at rcblue.com
Tue Oct 3 21:14:19 CEST 2006
At 11:38 AM 10/3/2006, Kent Johnson wrote:
>Normally you will need to either
>- make 'mine' be a package, by creating an empty file named
>site-packages\mine\__init__.py, and changing your imports to include the
>package name (from mine import mycalc), or
>- add site-packages\mine to sys.path, maybe by creating a .pth file.
>http://www.python.org/doc/2.4.3/lib/module-site.html
I went with your first way, and it works with a script in python25\dev:
# 1test-8.py
from mine import mycalc
print mycalc.numberCommas(12341234123)
>>>
Evaluating 1test-8.py
12,341,234,123
But fails here:
# 1test-9.py
from mine import mycalc
from mycalc import numberCommas
print numberCommas(12341234123)
>>>
Evaluating 1test-9.py
Traceback (most recent call last):
File "<string>", line 1, in <string>
ImportError: No module named mycalc
>>>
I guess I can live with that.
>Gee, maybe I should just invite you over and we can talk ;)
Careful now. I just might show up!
Dick
More information about the Tutor
mailing list