Warning about "for line in file:"

Piet van Oostrum piet at cs.uu.nl
Sat Feb 23 16:02:45 CET 2002

>>>>> Aldo Cortesi <aldo at nullcube.com> (AC) writes:

AC> ... but this would leave a discrepancy between the actual
AC> file position and the notional "read" position. Among other
AC> things, file.tell() would then give the wrong information,
AC> and file.write() would write to an unexpected location. 

AC> It looks like the only complete solution (short of changing
AC> the sematics by fiat) would be to keep the file descriptor
AC> offset correct by performing a seek after reading every
AC> line. Then again, this would probably kill any efficiencies
AC> gained by xreadlines...

But seeks would not work with pipes (e.g. stdin) or sockets.
Piet van Oostrum <piet at cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: P.van.Oostrum at hccnet.nl

More information about the Python-list mailing list