Really, really annoying problem
peter at engcorp.com
Thu Sep 21 08:47:07 CEST 2000
Although all of Fredrik's subsequent posts are completely on the mark (I
even borrowed Guido's time machine to look ahead and check!), here's
another way to approach this that might make it clearer.
Go into your recurse_test.py file and in place of the line that does
"file = open(...)", put the following line:
file = open("c:\ppdump.txt", "w")
Now try running the program. Doesn't it work now?
Now change that line to this one instead, *after* deleting the file
c:\ppdump.txt which may now be on your hard drive.
file = open("c:\ppdump.txt")
This gives you the error again, doesn't it? Without the "w" you are
asking to *read* the file, not create it and write to it.
In other words, the content of the string in filename is not necessarily
related to your problem. When you pointed everybody to the line with "#
THIS IS THE PROBLEM" in your original code, perhaps you were jumping to
If I'm wrong about the above, you are still skipping some critical
information in your description. Trust us: based on what you've given
us, Fredrik is right! :-)
Brett Lempereur wrote:
> > - how do you read in the filename?
> The filename is taken from the "sys.argv" property, that's why I need the
> function in the first place. The directory for the configuration files will
> either be "lib/config/" or "config/" with "lib" being the directory the code
> is placed in.
> > - 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
> 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'
More information about the Python-list