By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,035 Members | 1,388 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,035 IT Pros & Developers. It's quick & easy.

chdir()

P: n/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?

thanks,

jh

May 8 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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").

--
Jarek Zgoda
http://jpa.berlios.de/
May 8 '07 #2

P: n/a
On May 8, 3:54 pm, HMS Surprise <j...@datavoiceint.comwrote:
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

May 8 '07 #3

P: n/a
On Tuesday 08 May 2007 22:54:39 HMS Surprise wrote:
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

May 8 '07 #4

P: n/a
On Tue, 2007-05-08 at 12:54 -0700, HMS Surprise wrote:
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,

--
Carsten Haese
http://informixdb.sourceforge.net
May 8 '07 #5

P: n/a
On May 8, 3:06 pm, Carsten Haese <cars...@uniqsys.comwrote:
On Tue, 2007-05-08 at 12:54 -0700, HMS Surprise wrote:
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,

--
Carsten Haesehttp://informixdb.sourceforge.net
Thanks all. Windows bytes me again. I know better just wasn't
thinking. \n

May 8 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.