[Python-ideas] new format spec for iterable types

Stephen J. Turnbull stephen at xemacs.org
Wed Sep 9 04:37:20 CEST 2015


Oscar Benjamin writes:

 > ATM the colon separates the part of the format element that is
 > interpreted by the format method to find the formatted object from the
 > part that is passed to the __format__ method of the formatted object.
 > Perhaps an additional colon could be used to separate the separator
 > for when the formatted object is an iterable so that
 > 
 >      'foo {name:<fmt>:<sep>} bar'.format(name=<expr>)

I thought about a colon, but that loses if the objects are times.  I
guess that kills '/' and '-', too, since the objects might be dates.
Of course there may be a tricky way to use these that I haven't
thought of, or they could be escaped for use in <fmt>.



More information about the Python-ideas mailing list