chdir()

H

HMS Surprise

Tried executing os.chdir("c:\twill") from a python Tk shell and got
the error message:

WindowsError: [Error 123] The filename, directory name, or volume
label syntax is incorrect: 'c:\twill'.

I have the directory exists as I copied the name from the explorer
window that was open to it.

What is wrong with the syntax?

thanks,

jh
 
J

Jarek Zgoda

HMS Surprise napisa³(a):
Tried executing os.chdir("c:\twill") from a python Tk shell and got
the error message:

WindowsError: [Error 123] The filename, directory name, or volume
label syntax is incorrect: 'c:\twill'.

I have the directory exists as I copied the name from the explorer
window that was open to it.

What is wrong with the syntax?

Unescaped '\' character. Try with raw string (r"c:\twill") or escape it
("c:\\twill").
 
B

Basilisk96

Tried executing os.chdir("c:\twill") from a python Tk shell and got
the error message:

WindowsError: [Error 123] The filename, directory name, or volume
label syntax is incorrect: 'c:\twill'.

I have the directory exists as I copied the name from the explorer
window that was open to it.

What is wrong with the syntax?

thanks,

jh


Use
os.chdir(r"c:\twill")
instead.

The "\t" character is the escape character for a tab. You can avoid
such a faux pas by using the raw string construct of the form r"some
string". Otherwise, any backslashes in in your string will be
interpreted as escape characters.

-Basilisk96
 
N

Necmettin Begiter

WindowsError: [Error 123] The filename, directory name, or volume
label syntax is incorrect: 'c:\twill'.

What is wrong with the syntax?

Try 'c:\\twill' because the '\' character is the escape character.
Eg: \n is new-line (aka crlf)
\t is tab etc.

To understand how these work, try this:

print 'hello\nworld'

and you get:

hello
world
 
C

Carsten Haese

Tried executing os.chdir("c:\twill") from a python Tk shell and got
the error message:

WindowsError: [Error 123] The filename, directory name, or volume
label syntax is incorrect: 'c:\twill'.

Backslash-t is a tab character, so you're trying to chdir to
C:<tab>will, which is not a valid path name. Use a forward slash, double
up the backslash, or use a raw string literal:

os.chdir("c:/twill")
os.chdir("c:\\twill")
os.chdir(r"c:\twill")

HTH,
 
H

HMS Surprise

Tried executing os.chdir("c:\twill") from a python Tk shell and got
the error message:
WindowsError: [Error 123] The filename, directory name, or volume
label syntax is incorrect: 'c:\twill'.

Backslash-t is a tab character, so you're trying to chdir to
C:<tab>will, which is not a valid path name. Use a forward slash, double
up the backslash, or use a raw string literal:

os.chdir("c:/twill")
os.chdir("c:\\twill")
os.chdir(r"c:\twill")

HTH,

Thanks all. Windows bytes me again. I know better just wasn't
thinking. \n
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top