Message218872
If it fits on a line then it seems Counter's repr is used:
>>> pprint(Counter({i:i*i for i in range(10)}))
Counter({9: 81, 8: 64, 7: 49, 6: 36, 5: 25, 4: 16, 3: 9, 2: 4, 1: 1, 0: 0})
Otherwise It is shown as a dict (Counter is a dict subclass) if it is too
large (multi-line):
>>> pprint(Counter({i:i*i for i in range(10)}), width=20)
{0: 0,
1: 1,
2: 4,
3: 9,
4: 16,
5: 25,
6: 36,
7: 49,
8: 64,
9: 81}
the behaviour is weird but pprint doesn't promise that custom objects such
as Counter that can't be created using Python literals will be printed in a
reversible manner.
It seems there is a special support for some objects:
>>> pprint(frozenset({i for i in range(10)}))
frozenset({0, 1, 2, 3, 4, 5, 6, 7, 8, 9})
>>> pprint(frozenset({i for i in range(10)}), width=20)
frozenset({0,
1,
2,
3,
4,
5,
6,
7,
8,
9})
Perhaps the support for Counter could be added using functools.singledispatch
and/or __prettyprint__ hook from issue #7434 |
|
Date |
User |
Action |
Args |
2014-05-21 13:26:40 | akira | set | recipients:
+ akira, rhettinger, cool-RR |
2014-05-21 13:26:40 | akira | set | messageid: <1400678800.11.0.306859760863.issue21542@psf.upfronthosting.co.za> |
2014-05-21 13:26:40 | akira | link | issue21542 messages |
2014-05-21 13:26:38 | akira | create | |
|