Really, really annoying problem

Fredrik Lundh effbot at telia.com
Wed Sep 20 16:23:40 EDT 2000


Brett wrote:
> > - how do you know that the backslashes are doubled?
> >   (in other words, how did you print the filename?)
> 
> Because I do this:
> 
> filename = tools.addroot("ppdump.cfg")
> file = open(filename, "w")
> 
> The error occurs at the "open(filename, 'w')" stage, where it raises the
> double backslash error
> 
> The error message from python is....
> 
> Traceback (most recent call last):
>   File "D:\Python\Pythonwin\pywin\framework\scriptutils.py", line 301, in
> RunScript
>     exec codeObject in __main__.__dict__
>   File "C:\My Documents\Python\Backup Program\Lib\recurse_test.py", line 17,
> in ?
>     out_file = open(out_filename)
> IOError: [Errno 2] No such file or directory: 'C:\\ppdump.txt'

note the quotes around the filename -- tracebacks
use 'repr' too:

>>> filename = "spam\\egg"
>>> print filename
spam\egg
>>> file = open(filename)
Traceback (innermost last):
  File "<stdin>", line 1, in ?
IOError: [Errno 2] No such file or directory: 'spam\\egg'
>>> print filename
spam\egg
>>>

(also note that there's no "w" in your recurse_test script.
maybe that's the real problem here?)

</F>



More information about the Python-list mailing list