"Wayne Watson" <[EMAIL PROTECTED]> wrote
junkfile = open('c:\tmp\junkpythonfile','w')
IOError: [Errno 2] No such file or directory:
'c:\tmp\\junkpythonfile'
I suspect the problem is with the back slash. Comments?
Correct. There are several ways round this, the simplest
being to use forward slashes which are effectively portable
across most OSs.
junkfile = open('c:/tmp/junkpythonfile','w')
You could use a raw string by prefixing the string with r
junkfile = open(r'c:\tmp\junkpythonfile','w')
Or you could escape the backslash
junkfile = open('c:\\tmp\\junkpythonfile','w')
BTW, how does one continue a long statement
that has, say, a long path to a file?
You can create a long string by adding the shorter string
elements :
f = open(
"a:/very/long/path/name/that/needs/a/whole/line/to./itself.py",
"w")
becomes
f = open("a:/very/long/path/name/" +
"that/needs/a/whole/" +
"line/to./itself.py","w")
or by using a line continuation character.
f = open("a:/very/long/path/name/" \
"that/needs/a/whole/" \
"line/to./itself.py", "w")
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor