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

Gordon McMillan gmcm at hypernet.com
Tue May 18 10:48:14 EDT 1999


Oliver Steele writes:

> My reading of the Python Library documentation
> <http://www.python.org/doc/lib/bltin-file-objects.html> is that,
> regardless of file modes, f.seek(f.tell()) should be a noop
> (assuming f is bound to an open file):
/snip/
> Not so. On a Windows machine (specifically, an SGI running WindowsNT
> and Python 1.5.2 final), the function below prints 'a\012' for the
> first line and '\012' for the second.  Changing the file open mode
> to 'rb' or running the program on a Mac or UNIX machine works fine.
/snip/
> The upshot of this is that it's possible to develop a Python program
> under MacOS or UNIX, using the documentation available on those
> platforms, that fails under NT -- in other words, it demotes Python
> to the status of a 'write once test everywhere language'. 

I'm sorry that you got the impression that Python promises WORE. In 
general, Python is ever-so-slightly more portable than the underlying 
c runtime libs are conformant. WIth the low-level routines, you 
generally get your c runtime lib's behavior, warts and all. It's true 
that only a subset of the gotchas are documented, but that's a never 
ending task.

Someplace (probably the MSVC docs) I've seen the warning that seek
and tell are may be less-than-useful on a file opened in text mode. 

Languages which promise WORE are no more successful overall. And 
Python has the advantage that it's easy to work around the problem, 
while in that other language it's damn near impossible.

- Gordon




More information about the Python-list mailing list