Possible File iteration bug
nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de
Sun Jul 17 09:26:59 CEST 2011
Am 16.07.2011 05:42 schrieb Steven D'Aprano:
You are right - it is a very big step for a very small functionality.
> Or you can look at the various recipes on the Internet for writing tail-like
> file viewers in Python, and solve the problem the boring old fashioned way.
It is not only about this "tail-like" thing. There are other legitimate
use cases for this. I once found myself in the need to have a growing
list of data to be put into a database. This growth could, on one hand,
need several minutes to complete, but on the other hand the data should
be put into the database ASAP, but not too slow. So it was best to put
on every DB call all data which were present into the DB and iterate
over this until end of data.
Then, I wished such a PauseIteration exception as well, but there was
another, not-to-bad way to do it, so I did it this way (roughly, an
iterable whose iterator was exhausted if currently no data were present
and which had a separate method for signalling end of data.
while not source.done():
where put_to_db() iterates over source and issues the DB query with all
data available to this point and then starting over.
More information about the Python-list