This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: BasicModuleLoader behaviour in Python 2.3c2
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: ajaksu2, brett.cannon, georg.brandl, stuvi
Priority: normal Keywords:

Created on 2003-07-28 22:32 by stuvi, last changed 2022-04-10 16:10 by admin. This issue is now closed.

Messages (4)
msg17417 - (view) Author: Selim Tuvi (stuvi) Date: 2003-07-28 22:32
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.
msg17418 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-06-01 11:27
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.
msg17419 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-06-01 11:31
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.
msg81441 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-02-09 06:15
Even if the described behavior still occurs, looks like a won't fix.
History
Date User Action Args
2022-04-10 16:10:18adminsetgithub: 38956
2009-04-02 01:42:55brett.cannonsetstatus: open -> closed
resolution: wont fix
2009-02-11 03:02:04ajaksu2setassignee: brett.cannon
nosy: + brett.cannon
2009-02-09 06:15:13ajaksu2setnosy: + ajaksu2
type: behavior
messages: + msg81441
2003-07-28 22:32:07stuvicreate