Hi I am using the BasicModuleLoader class from the
ihooks module and noticed that it behaves differently
based on whether it is used from a script vs. from the
Python command line. Here is the transcript of my
session:
C:\projects\Online\repos>type testModule.py
C:\projects\Online\repos>cd ..\testsuite
C:\projects\Online\testsuite>type impTest.py
from ihooks import BasicModuleLoader
import os
os.chdir('../repos')
ml = BasicModuleLoader()
modstuff = ml.find_module('testModule')
print modstuff
C:\projects\Online\testsuite>python impTest.py
None
C:\projects\Online\testsuite>python
Python 2.3c2 (#45, Jul 24 2003, 21:23:54) [MSC v.1200
32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more
information.
>>> from ihooks import BasicModuleLoader
>>> import os
>>> os.chdir('../repos')
>>> ml = BasicModuleLoader()
>>> modstuff = ml.find_module('testModule')
>>> print modstuff
(<open file 'testModule.py', mode 'U' at
0x008E8F20>, 'testModule.py', ('.py', '
U', 1))
>>> ^Z
C:\projects\Online\testsuite>cd ..\repos
C:\projects\Online\repos>python ..\testsuite\impTest.py
(<open file 'C:\projects\Online\repos\testModule.py',
mode 'U' at 0x008E7F20>, '
C:\\projects\\Online\\repos\\testModule.py', ('.py', 'U',
1))
C:\projects\Online\repos>
Explanation of the above session:
I created an empty module called testModule.py and
stored it in c:\projects\Online\repos. Then I wrote the
impTest.py script that tries to import it through the
BasicModuleLoader. The impTest.py script resides in
c:\projects\Online\testsuite directory. If I run the script
from the testsuite directory it fails to find the module. If
while I am in the testsuite directory I enter the contents
of the impTest.py using the Python command line then it
finds the module. Also if I run the impTest.py while I am
in the repos directory then it finds it as well. In Python
2.2 this had worked in every case.
|