[Python-Dev] pprint(iterator)

Nick Coghlan ncoghlan at gmail.com
Tue Jan 27 23:14:37 CET 2009


Raymond Hettinger wrote:
>    <enumerate object: 'A', 'B', 'C', 'D', 'E', 'F'>

I quite like the idea of something along those lines. For example:

try:
  itr = iter(obj)
except TypeError:
  pass
else:
  return "<iterable %s: %s>" % (obj.__class__.__name__,
                                <as for list contents>))

Doing this only in pprint also reduces the chances of accidentally
consuming an iterator (which was a reasonable objection when I suggested
changing the __str__ implementation on some of the standard iterators
some time ago).

Cheers,
Nick.

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


More information about the Python-Dev mailing list