interaction of mode 'r+', file.write(), and file.tell(): a bug or undefined behavior?
aahz at pythoncraft.com
Tue Feb 2 00:29:55 CET 2010
In article <4b617f4a$1 at dnews.tpgi.com.au>,
Lie Ryan <lie.1296 at gmail.com> wrote:
>f = open('input.txt', 'r+')
>for line in f:
> s = line.replace('python', 'PYTHON')
> # f.tell()
>When f.tell() is commented, 'input.txt' does not change; but when
>uncommented, the f.write() succeeded writing into the 'input.txt'
>(surprisingly, but not entirely unexpected, at the end of the file).
Another possible issue is that using a file iterator is generally not
compatible with direct file operations.
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
More information about the Python-list