[Tutor] question about sys.path and importing
Kent Johnson
kent37 at tds.net
Tue Oct 3 21:30:56 CEST 2006
Dick Moores wrote:
> 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
> >>>
Well this is different code. Try what you did in the first one:
from mine import mycalc
print mycalc.numberCommas(12341234123)
or
from mine.mycalc import numberCommas
Kent
More information about the Tutor
mailing list