Really, really annoying problem

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


Brett wrote:
> There's gotta be a way around this.
> 
> Maybe a temporary string conversion of sorts...

sigh.

this is getting really, really annoying...

I'll summarize:

    to fix your code, add a "w" mode argument to
    the open statement in recurse_test.py

if you really want to know what's up with those back-
slashes, read my earlier posts again.

</F>

> Fredrik Lundh <effbot at telia.com> wrote in message
> news:g19y5.1228$n4.106912 at newsc.telia.net...
> > 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