RE: [PyCrust] problems with os
Brought to you by:
pobrien
From: Patrick K. O'B. <po...@or...> - 2001-09-07 22:26:57
|
The short answer is that what you see right now is the default behavior of the Python interpreter. The other shells, such as IDLE, play useful tricks by adding things to the sys.path behind the scenes. In particular, the following bit of code will illustrate what you want by adding the current directory, as represented by ".", to the sys.path. Then when you os.chdir() you will be able to import from the current working directory. >>> from pprint import pprint >>> import sys >>> pprint(sys.path) ['', 'C:\\Code', 'C:\\Python21\\win32', 'C:\\Python21\\win32\\lib', 'C:\\Python21', 'C:\\Python21\\Pythonwin', 'C:\\PYTHON21\\DLLs', 'C:\\PYTHON21\\lib', 'C:\\PYTHON21\\lib\\plat-win', 'C:\\PYTHON21\\lib\\lib-tk', 'C:\\PYTHON21\\Numeric'] >>> import os >>> sys.path.insert(0, os.curdir) >>> pprint(sys.path) ['.', '', 'C:\\Code', 'C:\\Python21\\win32', 'C:\\Python21\\win32\\lib', 'C:\\Python21', 'C:\\Python21\\Pythonwin', 'C:\\PYTHON21\\DLLs', 'C:\\PYTHON21\\lib', 'C:\\PYTHON21\\lib\\plat-win', 'C:\\PYTHON21\\lib\\lib-tk', 'C:\\PYTHON21\\Numeric'] Because this is pretty useful, I will probably add sys.path.insert(0, os.curdir) as standard behavior in the shell so you won't have to jump through this hoop in the future. In fact, I just checked this change into cvs. Hope this helps. Thanks for the feedback. --- Patrick K. O'Brien Orbtech (http://www.orbtech.com) "I am, therefore I think." -----Original Message----- From: pyc...@li... [mailto:pyc...@li...]On Behalf Of Raul Cota Sent: Friday, September 07, 2001 4:04 PM To: pycr Subject: [PyCrust] problems with os why doesn't this code work??? >>> import os >>> os.chdir('d:\sim') >>> import SThermoAdmin Traceback (most recent call last): File "<input>", line 1, in ? ImportError: No module named SThermoAdmin Needless to say , that I tested the same lines in another interpreter and they work fine. Tried it with any file that is not in the python path and I get the same results. I'll try to find the reason myself since I'm going to be playing around with PyCrust today, because I'm planning on implementing it in my application (currently I'm using shell.py that comes in the wxPython distribution) BTW. Thanks for the icon... it looks really cool!!! Raul Win NT; Python 2.1; wxPython 2.3.1 _______________________________________________ PyCrust-users mailing list PyC...@li... https://lists.sourceforge.net/lists/listinfo/pycrust-users |