[Python-3000] Format specifier proposal

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Aug 15 02:56:54 CEST 2007


Guido van Rossum wrote:
> On 8/13/07, Andrew James Wade <andrew.j.wade at gmail.com> wrote:
>>>On 2007年8月13日 20:53:26 -0700
>>"Guido van Rossum" <guido at python.org> wrote:

>>>I propose that their
>>>__format__ be defined like this:
>>>>>> def __format__(self, spec):
>>> return self.strftime(spec)
>>>>You loose the ability to align the field then.

This might be a use case for the chaining of format specs
that Ron mentioned. Suppose you could do
 "{{1:spec1}:spec2}".format(x)
which would be equivalent to
 format(format(x, "spec1"), "spec2")
then you could do
 "{{1:%Y-%m-%d %H:%M:%S}:<20}".format(my_date)
and get your date left-aligned in a 20-wide field.
(BTW, I'm not sure about using strftime-style formats
as-is, since the % chars look out of place in our new
format syntax.)
--
Greg


More information about the Python-3000 mailing list

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