overwrite bytes in file
Neal Norwitz
neal at metaslash.com
Wed Mar 27 07:39:13 EST 2002
Marcus Stojek wrote:
>
> Hi,
> how can I overwrite certain bytes in a file (Win NT) and
> keep the rest unchanged.
> All open options are truncating the file.
The mode should be 'r+'. On windows it would probably be better
to use 'rb+'.
>>> f = open('nn')
>>> print f.read()
test
>>> f = open('nn', 'r+')
>>> f.seek(2)
>>> f.write('a')
>>> f.close()
>>> f = open('nn')
>>> print f.read()
teat
Neal
More information about the Python-list
mailing list