[Tutor] Creating files inside a script [I made a mistake!]

Sheila King sheila@thinkspot.net
Sun, 22 Apr 2001 23:01:50 -0700


Thanks, Daniel, for your replies.

On Sat, 21 Apr 2001 20:34:03 -0700 (PDT), Daniel Yoo
<dyoo@hkn.eecs.berkeley.edu>  wrote about Re: [Tutor] Creating files inside a
script [I made a mistake!]:

:I meant to talk about "r+", not "a+".  I don't know why I insisted on
:talking about append, when it's "r+" that causes the IOError.  I apologize
:about this error again.
:
:
:In retrospect, it makes sense why "r+" is one that raises IOError: it
:means that we're assuming that the file exists and is good for reading and
:writing.  But like the regular "r" mode, if the file isn't there, then it
:will raise an IOError.

This is how I would have thought things work, and that is obviously what the
docs say. But, then I just don't get why I was getting this error:

  File "gypsymail.py", line 117, in PrintErrorToLogFile
    logfile = open(logfilename, 'a+')
IOError: (2, 'No such file or directory')

In any case, the script seems to be working fine, now. I changed that line of
my program to 
    logfile = open(logfilename, 'a')

since I'm only going to write to the file, anyway, and I don't need the a+
functionality. It now seems to create the file, when the file doesn't already
exist. Beats me, what the problem was before.

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/