Re: [Tutor] question about sys.path and importing

2006-10-03 Thread Dick Moores
At 12:30 PM 10/3/2006, you wrote:
>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 "", line 1, in 
>>ImportError: No module named mycalc
>>  >>>
>
>Well this is different code.

Yes, that was my point. Sorry I didn't make that clear.

>Try what you did in the first one:
>from mine import mycalc
>print mycalc.numberCommas(12341234123)
>
>or
>from mine.mycalc import numberCommas

Good! Didn't know I could do "from mine.mycalc import numberCommas".

Thanks,

Dick



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] question about sys.path and importing

2006-10-03 Thread Kent Johnson
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 "", line 1, in 
> 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

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] question about sys.path and importing

2006-10-03 Thread Dick Moores
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 "", line 1, in 
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

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] question about sys.path and importing

2006-10-03 Thread Kent Johnson
Dick Moores wrote:
> This morning I was sternly warned by Wingware support not to leave my 
> module of useful functions in Python25\Lib. So I put it in a 
> subfolder in site-packages I named "mine". Importing of or from that 
> module, mycalc.py goes well, to my surprise, because of
> 
>  >>> import sys
>  >>> [x for x in sys.path if "site-packages" in x]
> ['e:\\Python25\\lib\\site-packages', 
> 'e:\\Python25\\lib\\site-packages\\win32', 
> 'e:\\Python25\\lib\\site-packages\\win32\\lib', 
> 'e:\\Python25\\lib\\site-packages\\Pythonwin', 
> 'e:\\Python25\\lib\\site-packages\\wx-2.6-msw-unicode']
>  >>>
> 
> in which "mine" isn't included, even though other folders in site-packages 
> are.
> 
> Can someone explain this, please?

If the program that does the import is also in site-packages\mine, that 
would explain it. When you run a script its directory is added to sys.path.

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

Gee, maybe I should just invite you over and we can talk ;)

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] question about sys.path and importing

2006-10-03 Thread Dick Moores
This morning I was sternly warned by Wingware support not to leave my 
module of useful functions in Python25\Lib. So I put it in a 
subfolder in site-packages I named "mine". Importing of or from that 
module, mycalc.py goes well, to my surprise, because of

 >>> import sys
 >>> [x for x in sys.path if "site-packages" in x]
['e:\\Python25\\lib\\site-packages', 
'e:\\Python25\\lib\\site-packages\\win32', 
'e:\\Python25\\lib\\site-packages\\win32\\lib', 
'e:\\Python25\\lib\\site-packages\\Pythonwin', 
'e:\\Python25\\lib\\site-packages\\wx-2.6-msw-unicode']
 >>>

in which "mine" isn't included, even though other folders in site-packages are.

Can someone explain this, please?

Dick Moores

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor