[Tutor] How to change the working directory in IDLE

Martin Walsh mwalsh at mwalsh.org
Wed Jun 17 00:04:20 CEST 2009


Elisha Rosensweig wrote:
> Hi Tutors,
> 
> I"m using Python 2.6.2 and the IDLE tool (also v. 2.6.2). However, when
> I open the editor I cannot seem to change the directory so as to allow
> for easy access to my modules. So, for example, the following occurs:
> 
>>>>
> os.chdir('/Users/elisha/Documents/workspace/CacheNetFramework/src/Tests')
>>>> os.getcwd()
> '/Users/elisha/Documents/workspace/CacheNetFramework/src/Tests'
>>>> import CSITest
> 
> Traceback (most recent call last):
>   File "<pyshell#9>", line 1, in <module>
>     import CSITest
> ImportError: No module named CSITest
> 
> 
> What am I doing wrong?

http://docs.python.org/tutorial/modules.html#the-module-search-path

You probably want to append to sys.path in your script, or to the
PYTHONPATH environment variable, instead of using os.chdir.

import sys
sys.path.append('/Users/elisha/Documents/workspace/CacheNetFramework/src/Tests')

import CSITest

HTH,
Marty


More information about the Tutor mailing list