Reading a file and then writing something back
Kevin T. Ryan
kevryan0701 at yahoo.com
Wed Jul 21 09:16:17 EDT 2004
Hi All -
I'm not sure, but I'm wondering if this is a bug, or maybe (more
likely) I'm misunderstanding something...see below:
>>> f = open('testfile', 'w')
>>> f.write('kevin\n')
>>> f.write('dan\n')
>>> f.write('pat\n')
>>> f.close()
>>> f = open('testfile', 'r+')
>>> f.readline()
'kevin\n'
>>> f.readline()
'dan\n'
>>> f.write('chris\n')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
IOError: (0, 'Error')
I've figured out that I can do an open('testfile', 'r+') and then seek
and write something (without an error), but it just seems odd that I
would get an IOError for what I was trying to do. Oh, and I also
tried to do "f.flush()" before the write operation with no luck.
I've searched google, but can't seem to find much. Any thoughts???
TIA,
Kevin
More information about the Python-list
mailing list