[Python-3000] Need Decimal.__format__
Nicko van Someren
nicko at nicko.org
Fri Aug 31 14:01:35 CEST 2007
On 31 Aug 2007, at 02:36, Talin wrote:
...
> Also, I'm interested in suggestions as to any other standard types
> that
> ought to have a __format__ method, other than the obvious Date/Time
> classes. What kinds of things do people usually want to print?
For years I've thought that various collection types would benefit
from better formatters. If space is limited (e.g. fixed width
fields) then lists, tuples and sets are often better displayed
truncated, with an ellipsis in lieu of the remainder of the
contents. Being able to have a standard way to print your list as
[2, 3, 5, 7, 11,...] when you only have 20 characters would
frequently be useful. Having a formatter directive for collections
to ask for the contents without the enclosing []/()/{} would also be
useful.
It's not clear to me that there's much to be gained from building in
more complex formatters for dictionary-like objects, since it will be
hard to describe the plethora of different ways it could be done, and
while having multi-line formatting options for long lists/sets would
be nice it may deviate too far from the standard usage of string
formatting, but displaying simple collections is a sufficiently
common task that I think it's worth looking at.
Nicko
More information about the Python-3000
mailing list