[Python-Dev] pprint(iterator)

Nick Coghlan ncoghlan at gmail.com
Thu Jan 29 22:54:35 CET 2009


Michael Foord wrote:
> Don't we have a pretty-print API - and isn't it spelled __str__ ?

For the "reiterable" cases like dictionary views (where the object is
not consumed), an appropriate __str__ or __repr__ should be written).

Whether that is something as simple as "<repr of underlying
dict>.items()" for an items view, or something more complicated that
more directly shows the content of the view, I'm not sure.

For the standard iterators like enumerate and ranged, I would suggest
that they be modified to use a repr of the form:

"reversed(<repr of underlying iterable>)"
"enumerate(<repr of underlying iterable>)"
"iter(<repr of underlying sequence>)"
"iter(<repr of callable>, <repr of sentinel value>)"

While those obviously won't show how much of the iterable has been
consumed, neither do the current representations.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------


More information about the Python-Dev mailing list