module path:funny bug, funny solution
Siggy Brentrup
bsb at winnegan.de
Thu Jan 6 04:21:29 EST 2000
More information about the Python-list mailing list
Thu Jan 6 04:21:29 EST 2000
- Previous message (by thread): Who hosts CGI/Python?
- Next message (by thread): module path:funny bug, funny solution
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Pierre Imbaud <pierre at saiph.com> writes: > 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... There is no need to chdir just for reloading modules, simply change sys.path[0] upon startup. If you are concerned about others looking at your code, you might use the technique from the attached files # Siggy -- Siggy Brentrup - bsb at winnegan.de - http://www.winnegan.de/ ****** ceterum censeo javascriptum esse restrictam ******* -------------- next part -------------- A non-text attachment was scrubbed... Name: debugging.py Type: application/octet-stream Size: 265 bytes Desc: not available URL: <http://mail.python.org/pipermail/python-list/attachments/20000106/5e80ed7e/attachment.obj> -------------- next part -------------- A non-text attachment was scrubbed... Name: debugme.py Type: application/octet-stream Size: 162 bytes Desc: not available URL: <http://mail.python.org/pipermail/python-list/attachments/20000106/5e80ed7e/attachment-0001.obj>
- Previous message (by thread): Who hosts CGI/Python?
- Next message (by thread): module path:funny bug, funny solution
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list