chdir questions

Thomas A. Bryan tbryan at python.net
Sun Feb 6 08:16:15 EST 2000


Patrick K Moorman wrote:

> I know this is must be an easy one but how do I use os.chdir?  

>>> os.chdir('C:\\temp')

or 

>>> os.chdir(r'C:\temp')

You need the two backslashes (or the "raw string") simply because 
the a single backslash followed by the letter t will expand to a 
tab in a normal string.

>>> print 'C:\temp'
C:      emp
>>> print 'C:\\temp'
C:\temp
>>> print r'C:\temp'
C:\temp

I would normally recommend that you look at the docstring or the 
source, but the docstring says 

>>> print os.chdir.__doc__
chdir(path) -> None
Change the current working directory to the specified path.

which wouldn't have helped, and I can't seem to find any definition 
for os.chdir in the Python libraries. It's defined *somewhere*, and 
I'm sure that someone will show me where.  One of the greatest things 
about open source is that you're never really stuck.  For example, if 
you can't figure out how to use glob, you can always look at glob.py 
to see what it does.

---Tom



More information about the Python-list mailing list