[Pythonmac-SIG] Frustration building, please help...

Chris Scott kaffeen@mac.com
Sat, 03 Nov 2001 23:45:58 -0500


Hi Russell -
Thanks for the input, no question can ever be fully answered. At least,
not for the Python newbie! And if you must know, I was opening the file
as "r+" because the tutorial said I could. So, if I can, then I want
to:) There's no application, I'm just trying to get through the
text/file IO/rules and regs stuff so I can start working on games. I
suppose, somewhere in the back of my head, was an idea of a simple word
processor. Again, thanks for the help. I look forward to asking more
questions!
- Chris


 Subject:
         Re: [Pythonmac-SIG] Frustration building, please help...
    Date:
         Fri, 2 Nov 2001 09:34:08 -0800
   From:
         Russell E Owen <owen@astro.washington.edu>
     To:
         Mac Python mailing list <pythonmac-sig@python.org>



Others have already answered the overall question, but there is one more
point I'd like to note: if you are going to use 'r+' mode, you must be
sure to flush all output to the file before attempting to read the file.

I don't believe that f.write() and f.writelines() are guaranteed to
flush their output, so I would recommend you do it explicitly with
f.flush() before attempting any read (and then seek to the beginning of
the file). In other words:
f.write...
f.flush()
f.seek(0)
f.read...

If you don't mind writing more, I'd be curious what application you
have, for which you are using a file that is simultaneously open for
read and write. (Both out of curiosity -- it's something I've thought
about using over the years but never actually ended up doing -- and
because we might be able to suggest a simpler design).

-- Russell