stdin - seek() issue on Linux.

Donn Cave donn at drizzle.com
Wed Apr 24 01:19:55 EDT 2002


Quoth "Noah" <noah at noah.org>:
| On the other hand, perhaps the File object could be more consistent.
| In some cases seek() will throw an IOError exception, but in
| other cases it will do nothing (no-op). For example if you
| call seek on disk files opened for writing in append mode (mode 'a') 
| then seek will be do nothing (no-op)... Hmmm... 
| I wonder why it throws an exception in some cases, but does nothing in others.

The rules, and their application, come from the C library stdio
implemention.  Python doesn't second-guess it - if it says the seek
was good, it was good.  And in fact, it was good, inasmuch as the
file pointer did move as specified.  But when a file was opened in
append mode, that means that every write goes to the end of the
file, period, like there's an implicit seek.  So you're right that
the seek() wouldn't have any practical effect.

	Donn Cave, donn at drizzle.com



More information about the Python-list mailing list