[Python-Dev] pprint(iterator)
Eric Smith
eric at trueblade.com
Fri Jan 30 07:58:35 CET 2009
Terry Reedy wrote:
> Ron Adam wrote:
>>
>>
>> Steven D'Aprano wrote:
>>> Michael Foord wrote:
>>>
>>>> Don't we have a pretty-print API - and isn't it spelled __str__ ?
>>>
>>> Not really. If it were as simple as calling str(obj), there would be
>>> no need for the pprint module.
>>
>> I agree. And when I want to use pprint, there are usually additional
>> output formatting requirements I need that isn't a "one size fits all"
>> type of problem.
I don't see how you can have a standard interface (like __pprint__), and
have additional, per-object formatting parameters. But that's beside the
point, I don't like __pprint__ in any event. Too special.
> Like others, I am wary of over-expanding the list of special methods.
> Perhap format strings could have a fourth conversion specifier, !p
> (pretty) in addition to !s, !r, and !a.
What would format() do with "!p"? With "!s", it calls str(o), with "!r",
it calls repr(o). "!p" could call o.__pprint__(), but that's the special
method you're trying to avoid!
(I don't recall if I added "!a", and a machine that would know isn't
available to me just now.)
Eric.
More information about the Python-Dev
mailing list