[Python-Dev] pprint(iterator) (original) (raw)
Steven D'Aprano steve at pearwood.info
Thu Jan 29 23:42:15 CET 2009
- Previous message: [Python-Dev] pprint(iterator)
- Next message: [Python-Dev] pprint(iterator)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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. In any case, it seems that the pprint module actually calls repr() on objects other than dicts, tuples and lists.
I'm concerned about the number of special methods exploding, but I've also come across times where I needed more than two string representations of an object. Sometimes I solved this by adding a pprint() method, other times I used other names, and it would be nice if there was a standard way of spelling it. So I'm +0.5 on Aahz's suggestion of pprint.
In my ideal world, pprint should allow (but not require) extra arguments, so that one can do something like the following:
pprint(binarytree) # sensible defaults pprint(binarytree, order='preorder')
-- Steven
- Previous message: [Python-Dev] pprint(iterator)
- Next message: [Python-Dev] pprint(iterator)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]