[Tutor] function won't import from module

Dick Moores rdm at rcblue.com
Tue Aug 9 12:35:07 CEST 2005


Alan G wrote at 03:22 8/9/2005:
>>I tried deleting a mycalc.pyc that had been created and the problem 
>>cleared up! If I remember correctly, for a while I had moved mycalc.py 
>>to another folder in PYTHONPATH (I had recently learned how to modify 
>>PYTHONPATH in Win XP), and the .pyc was in this folder. Sorry I don't 
>>remember clearly. But what is clear is the problem cleared up 
>>immediately after deleting the .pyc. Does this make sense?
>
>Definitely. If the old pyc file was found first in the search path
>then it would have been imported. If the py and pyc are inthe same folder
>that won't be a problem because Python will see both and check the
>modification date but if it finds an isolated pyc first it will
>just use that.
>
>Alan G.

 >>> import sys
 >>> sys.path
['C:\\Python24\\Lib\\idlelib', 'C:\\Python24', 'C:\\Python24\\MyScripts', 
'C:\\Python24\\MyBestScripts', 'C:\\WINDOWS\\system32\\python24.zip', 
'C:\\Documents and Settings\\Dick', 'C:\\Python24\\DLLs', 
'C:\\Python24\\lib', 'C:\\Python24\\lib\\plat-win', 
'C:\\Python24\\lib\\lib-tk', 'C:\\Python24\\lib\\site-packages', 
'C:\\Python24\\lib\\site-packages\\Numeric', 
'C:\\Python24\\lib\\site-packages\\win32', 
'C:\\Python24\\lib\\site-packages\\win32\\lib', 
'C:\\Python24\\lib\\site-packages\\Pythonwin']

the pyc was in C:\\Python24, and mycalc.py had been moved back to 
C:\\Python24\\MyScripts. Does the order of folders in the output of 
sys.path determine the order of looking for a mycalc.* to execute?

Thanks,

Dick




More information about the Tutor mailing list