open filename with spaces in path

Chris cwitts at gmail.com
Wed May 7 10:00:48 EDT 2008


On May 7, 3:25 pm, "A.T.Hofkamp" <h... at se-162.se.wtb.tue.nl> wrote:
> On 2008-05-07, Chris <cwi... at gmail.com> wrote:
>
> >>>> os.chdir('C:\temp\my test')
> > Traceback (most recent call last):
> >   File "<input>", line 1, in <module>
> > WindowsError: [Error 123] The filename, directory name, or volume
> > label syntax is incorrect: 'C:\temp\\my test'
>
> Python strings have \ escapes, such as \t, \n etc. Above you try to go to
>
> C:<TAB>emp\my test
>
> and you are lucky that \m is not something special.
>
> Either escape your back slashes ("C:\\temp\\my test") or use raw strings
> (r"C:\temp\my test").
>
> Sincerely,
> Albert

My personal preference is using backslashes, if it's something quick
or if it's something that will be sitting on a server in a dark corner
for a long time to just use os.path.join.  I've had neither of those 2
break on me. ;)



More information about the Python-list mailing list