Newbie need help

Peter Hansen peter at engcorp.com
Mon Apr 5 08:33:49 EDT 2004


Tony Ha wrote:

> Question from a newbie. 
> 
> In the interactive Python shell.
> 
> 1. How do I find out where I am in the file system under WindowXP?
> 
>    I try os.curdir, which only give '.' back, I would like a full path
> like the Unix 'pwd' give.

Cameron answered that.  Note that os.curdir isn't even a function
call, so it is really just returning "the symbol which represents
the current directory in paths".

> 2. How do I change directory under WindowXp?
> 
>    I try os.chdir('C:\Downloads\Python\SOAPpy-0.11.3\fpconst-0.6.0')
> but I get the following Error message:

Learn about escape sequences in strings.  You have a \f in the
above, which translates into an ASCII formfeed character.  The
other three are all (I believe) "safe" since there is no
corresponding escape sequence but that's just luck.

Use either a "raw string" (exactly what you wrote above, but with
a lowercase r in front of the string as in r'C:\Downloads .....)
or switch to using forward slashes as much as possible, since they
will work as long as the shell is not going to see your path
(which is the case with a simple chdir among many other things).

-Peter



More information about the Python-list mailing list