is_iterable function.

Carsten Haese carsten at uniqsys.com
Wed Jul 25 15:47:50 EDT 2007


On Wed, 2007-07-25 at 19:26 +0000, Neil Cerutti wrote:
> Speaking of the iter builtin function, is there an example of the
> use of the optional sentinel object somewhere I could see?

Example 1: If you use a DB-API module that doesn't support direct cursor
iteration with "for row in cursor", you can simulate it this way:

for row in iter(cursor.fetchone, None):
   # do something

Example 2: Reading a web page in chunks of 8kB:

f = urllib.urlopen(url)
for chunk in iter(lambda:f.read(8192), ""):
  # do something

HTH,

-- 
Carsten Haese
http://informixdb.sourceforge.net





More information about the Python-list mailing list