Proposed new PEP: print to expand generators
Terry Reedy
tjreedy at udel.edu
Sat Jun 3 22:02:55 EDT 2006
"James J. Besemer" <jb at cascade-sys.com> wrote in message
news:4482390E.7060809 at cascade-sys.com...
> I propose that we extend the semantics of "print" such that if the object
> to
> be printed is a generator then print would iterate over the resulting
> sequence of sub-objects and recursively print each of the items in order.
A generator is an iterator produced by a generator function rather than a
class. What treat them differently?
Iterating over an iterator is usually destructive. So you would be
printing what it was but no longer is. This is why iterators are printed
differently from sequences.
Terry Jan Reedy
More information about the Python-list
mailing list