File modes

HMS Surprise john at datavoiceint.com
Thu May 10 16:47:20 EDT 2007


After reading a file is it possible to write to it without first
closing it? I tried opening with 'rw' access and re-winding. This does
not seem to work unless comments are removed.

Also, does close force a flush?

Thanks,

jh

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

f = open('c:\\tempMaxq\\incidents.txt', 'rw')
s = f.read()
lst = s.split()
incId = []
incId.extend([lst.pop(), lst.pop()])
#f.close()
#f = open('c:\\tempMaxq\\incidents.txt', 'w')
#f.seek(0)
for el in lst:
    f.write(el + ' ')
f.close()




More information about the Python-list mailing list