Bug? On WindowsNT, f.seek() and f.tell() aren't symmetric

Fredrik Lundh fredrik at pythonware.com
Wed May 19 05:28:43 EDT 1999


Oliver Steele wrote:
>     # create a two-line file
>     f = open('test.txt', 'wb')
>     f.write('a\nb\n')
>     f.close()

nice try.  since you open the file in binary
mode, that's a file with two LF characters
in it, which is not necessarily a two line
text file.

if you get rid of that 'b', your code will pro-
duce native text files, and it'll work on both
Unix and NT (and probably the Mac as well).

if you add a 'b' to the second open statement
(that is, read the file in binary mode), you'll
produce Unixish text files, and it'll work on
both Unix and NT (though probably not on
the Mac).

</F>





More information about the Python-list mailing list