Python open of c:\ path Problem

Tim Golden mail at timgolden.me.uk
Sat Aug 23 16:07:28 CEST 2008


Wayne Watson wrote:
> Python doesn't like this:
> 
> junkfile = open('c:\tmp\junkpythonfile','w')
> 
> I get
>     junkfile = open('c:\tmp\junkpythonfile','w')
> IOError: [Errno 2] No such file or directory: 'c:\tmp\\junkpythonfile'


The clue, if you needed one, is there in that traceback.
Notice the *single* slash before the "t" in contrast
with the *double* slash before the "j".

In short, you need to double up your backslashes,
or use a raw string or forward slashes. There's an
FAQ somewhere but I can't be bothered to look for
it right now.

TJG



More information about the Python-list mailing list