dumping generator

Peter Otten __peter__ at web.de
Mon Aug 9 06:40:47 EDT 2010


targetsmart wrote:

> Right now if I want to dump the contents of a generator object I use ,
> a snip from a bigger block of code..
> 
> try:
>  while gen:  print gen.next()
> except StopIteration:
>  print "Done"
> else:
>  raise
> 
> is there a much simpler way ?

Indeed there is:

for item in gen:
    print item
print "Done"

Peter




More information about the Python-list mailing list