module path:funny bug, funny solution
Pierre Imbaud
pierre at saiph.com
Wed Jan 5 18:49:08 EST 2000
I run into a funny bug, working on a python script, importing modules
laying in the same directory. The script performed some chdir. I debug
under xemacs, executing the script with py-execute-buffer. At some
point, I had to modify an imported module: I put a reload(module) in
the code: surprise! raises a "ImportError: No module named xx"!
what happens is quite simple: sys.path[0] is '', that means: first
search for modules in the current directory. First time, modules are
found ok. when trying to reload, the current directory has changed!
Now, I think its funny. I didnt when it happened.
The solution I found? between import os and import custom modules:
try:
os.chdir(startDirectory) # succeeds at subsequent runs
except:
startDirectory = os.getcwd() # run at first run.
well, it works, but may I let such a puzzle in my code? The
unadvertized reader will think Im plain mad...
--
Pierre Imbaud <pierre at saiph.com>
12 Rue des Bosquets 91480 Quincy Sous Sénart France
Tel: 01 69 00 94 57 Fax 79 65
More information about the Python-list
mailing list