Newbie need help

T

Tony Ha

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.

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:

Traceback (most recent call last):
File "<input>", line 1, in ?
OSError: [Errno 22] Invalid argument: 'C:\\Downloads\\Python\\SOAPpy-0.11.3
\x0cpconst-0.6.0'


Can any body help, thanks!!
 
C

Cameron Laird

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.
.
.
.
print os.getcwd()
 
T

Tony Ha

(e-mail address removed) (Cameron Laird) wrote in @corp.supernews.com:
.
.
.
print os.getcwd()

Hello Cameron,

Thanks, you help also help me to solve my 2nd question, it need "\\"
in the path instead of "\"
i.e. instead of os.chdir("C:\Python23\Lib\site-packages\PythonCardPrototype
\tools"

you need os.chdir("C:\\Python23\\Lib\\site-packages\\PythonCardPrototype
\\tools\\codeEditor")


Thanks again!!
 
P

Peter Hansen

Tony said:
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
 
T

Tony Ha

(e-mail address removed) (Cameron Laird) wrote in @corp.supernews.com:


Hello Cameron,

Thanks, you help also help me to solve my 2nd question, it need
"\\"
in the path instead of "\"
i.e. instead of
os.chdir("C:\Python23\Lib\site-packages\PythonCardPrototype \tools"

you need
os.chdir("C:\\Python23\\Lib\\site-packages\\PythonCardPrototype
\\tools\\codeEditor")


Thanks again!!

Hello,

I also found out you can you u' raw string. i.e.
os.chdir(u'C:\Python23\Lib\site-packages\PythonCardPrototype')
this also work.
 
S

Scott David Daniels

Tony said:
... instead of
os.chdir("C:\Python23\Lib\site-packages\PythonCardPrototype\tools")
you need
os.chdir("C:\\Python23\\Lib\\site-packages\\PythonCardPrototype\\tools\\codeEditor")
I also found out you can you u' raw string. i.e.
os.chdir(u'C:\Python23\Lib\site-packages\PythonCardPrototype')
this also work.
Nope, you just lucked out by using a different string.

the problem with using a backslash is that it normally an instruction to
the source translator to construct special characters. Because your
previous directory name included tools, you had a sequence with a
backslash followed by a lower case t. That is shorthand for a tab
(ASCII 9). As Peter Hansen tells you in another note, you can use
an r directly before the string to tell the source translator to
"treat backslashes as regular characters." So, you'll notice that,
for example, 'abc\tex' != r'abc\tex', but 'abc\Tex' == r'abc\Tex',
because '\t' is the tab character, not '\T'.
 
D

Dang Griffith

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.

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:

Traceback (most recent call last):
File "<input>", line 1, in ?
OSError: [Errno 22] Invalid argument: 'C:\\Downloads\\Python\\SOAPpy-0.11.3
\x0cpconst-0.6.0'


Can any body help, thanks!!
Other folks answers are true, but you also might look into install
IPython. It's a shell around the standard python interactive shell,
and it provides commands like pwd and cd and so forth.
You can get it at "http://ipython.scipy.org".
--dang
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,181
Messages
2,570,970
Members
47,537
Latest member
BellCorone

Latest Threads

Top