Python open of c:\ path Problem

Fredrik Lundh fredrik at
Sat Aug 23 16:08:01 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'

"\" is used as an escape character in string literals, so "\t" doesn't 
mean what you think it does.  see

for details.

to work around this, use double backslashes ("foo\\bar"), raw strings 
(r"foo\bar"), or, usually easiest, forward slashes ("foo/bar").


More information about the Python-list mailing list