homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author akira
Recipients akira, cool-RR, rhettinger
Date 2014年05月21日.13:26:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1400678800.11.0.306859760863.issue21542@psf.upfronthosting.co.za>
In-reply-to
Content
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 
History
Date User Action Args
2014年05月21日 13:26:40akirasetrecipients: + akira, rhettinger, cool-RR
2014年05月21日 13:26:40akirasetmessageid: <1400678800.11.0.306859760863.issue21542@psf.upfronthosting.co.za>
2014年05月21日 13:26:40akiralinkissue21542 messages
2014年05月21日 13:26:38akiracreate

AltStyle によって変換されたページ (->オリジナル) /