pprinting generators
Steve Holden
sholden at holdenweb.com
Fri Jun 28 10:04:42 EDT 2002
"Ville Vainio" <vvainio at tp.spt.fi> wrote ...
> On 2.2.1, pprint.pprint doesn't seem to be able to handle generators:
>
>
> >>> from __future__ import generators
> >>> def f(): yield 0
> ...
> >>> import pprint
> >>> pprint.pprint(f())
> <generator object at 0x007F91D0>
>
> Surely pprint could be more helpful with generators, iterating through
> them fully or just n first elements, or whatever. Or is this a design
> decision with pprint?
>
It wouldn't be very helpful of pprint to exhaust the generator so you
couldn't access the values, would it? What if the generator were infinite?
once-you-call-next()-there's-no-going-back-ly y'rs - steve
-----------------------------------------------------------------------
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------
More information about the Python-list
mailing list