How does f=open('mytext.txt', 'w+') work?

Alex lidenalex at yahoo.se
Sun Sep 18 13:30:37 EDT 2005


Yes the problem seems to be exactly that. I'm moving around the file
pointer. This piece of code works. Observe the only thing I've added is
f.seek(0)

>>> f=open('mytext.txt', 'w+')
>>> f.write('My name is Bob')
>>> f.seek(0)
>>> s=f.read()
>>> print s
My name is Bob
>>> f.close()

I've found this piece of clue at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_fopen.2c_._wfopen.asp
"However, when you switch between reading and writing, there must be an
intervening fflush, fsetpos, fseek, or rewind operation. The current
position can be specified for the fsetpos or fseek operation, if
desired."




More information about the Python-list mailing list