Hi all,
Working with read and write operations on a file I stumbled on a
complication when writes fail following a read to the end.
30L
'abcdefg'
Traceback (most recent call last):
File "<pyshell#6 2>", line 1, in -toplevel-
f.write ('abcdefg')
IOError: (0, 'Error')
Flushing doesn't help. I found two work arounds:
'abcdefg'
''
(No error)
'abcdefg'
it is!)
(No error)
I found no problem with writing into the file. So it looks like it has
to do with the cursor which a read puts past the end, unless it is past
the end, in which case it goes back to the end. Is there a less kludgy
alternative to "fseek (ftell ())"?
Frederic
Working with read and write operations on a file I stumbled on a
complication when writes fail following a read to the end.
>>f = file ('T:/z', 'r+b')
>>f.write ('abcdefg')
>>f.tell ()
>>f.write ('abcdefg')
>>f.tell ()
>>f.seek (0)
>>f.read ()
>>f.read ()
>>f.flush () # Calling or not makes no difference
>>f.write ('abcdefg')
>>f.write ('abcdefg')
File "<pyshell#6 2>", line 1, in -toplevel-
f.write ('abcdefg')
IOError: (0, 'Error')
Flushing doesn't help. I found two work arounds:
>>f.read ()
>>f.read () # Workaround 1: A second read (returning an empty string)
>>f.write ('abcdefg')
>>f.read ()
>>f.seek (f.tell ()) # Workaround 2: Setting the cursor (to where
>>f.write ('abcdefg')
I found no problem with writing into the file. So it looks like it has
to do with the cursor which a read puts past the end, unless it is past
the end, in which case it goes back to the end. Is there a less kludgy
alternative to "fseek (ftell ())"?
Frederic