Possible File iteration bug

T

Thomas Rachel

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.

Roughly:

while not source.done():
put_to_db(source)

where put_to_db() iterates over source and issues the DB query with all
data available to this point and then starting over.


Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top