[Python-ideas] new format spec for iterable types

random832 at fastmail.us random832 at fastmail.us
Tue Sep 8 21:38:04 CEST 2015



On Tue, Sep 8, 2015, at 12:27, Stephen J. Turnbull wrote:
> I'm afraid this won't work unless restricted to be the last
> replacement field, where it just consumes all remaining positional
> arguments.  I think that restriction deserves a loud "ugh", but maybe
> it will give somebody a better idea.

So, this is the second time in as many weeks that I've suggested a new
!converter, but this seems like the place for it - have something like
"!join" which "converts" [wraps] the argument in a class whose
__format__ method knows how to join [and call __format__ on the
individual members].

So you could make a list of floating point numbers by "List: {0:,
|.2f!join}".format([1.2, 3.4, 5.6])

and it will simply call Joiner([1.2, 3.4, 5.6]).__format__(", |.2f")


More information about the Python-ideas mailing list