Difference between readlines() and iterating on a file object?
Roy Smith
roy at panix.com
Fri Aug 13 11:11:02 EDT 2004
Christopher T King <squirrel at WPI.EDU> wrote:
> Assuming you don't prematurely exit the for loop or access the file in
> another manner while looping, both forms should give identical results.
> Otherwise...
Well, there is a corner case if some external process is writing to the
file while you're reading it. The "in file.readlines():" version will
get a snapshot of the file at the time you read it, while the "in file:"
version will do a sequence of reads over time.
Not that I think this is what's going on in the OP's case, but it's
something to be aware of.
More information about the Python-list
mailing list