[ python-Bugs-779191 ] BasicModuleLoader behaviour in Python 2.3c2

SourceForge.net noreply at sourceforge.net
Wed Jun 1 13:27:32 CEST 2005


Bugs item #779191, was opened at 2003-07-29 00:32
Message generated for change (Comment added) made by birkenfeld
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=779191&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
>Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Selim Tuvi (stuvi)
Assigned to: Nobody/Anonymous (nobody)
Summary: BasicModuleLoader behaviour in Python 2.3c2

Initial Comment:
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.


----------------------------------------------------------------------

>Comment By: Reinhold Birkenfeld (birkenfeld)
Date: 2005-06-01 13:27

Message:
Logged In: YES 
user_id=1188172

This is not a fault in ihooks but in the imp module; ihooks
just uses this.

The difference is that in the interactive interpreter,
sys.path contains an empty string (which is equivalent to
the current directory), while when executing a file,
sys.path contains the absolute path to the .py file. So the
path you chdir'd to is not on the module search list.

I don't know if that's intended behaviour.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=779191&group_id=5470


More information about the Python-bugs-list mailing list