[Python-3000] Format specifier proposal

Jim Jewett jimjjewett at gmail.com
Thu Aug 16 01:41:59 CEST 2007


On 8/15/07, Ron Adam <rrr at ronadam.com> wrote:
> After each term is returned from the __format__ call, the results
> __format__ method is called with the next specifier. GetTime.__format__
> returns a string. str.__format__, aligns it. A nice left to right
> sequence of events.

Is this a pattern that objects should normally follow, or a convention
enforced by format itself? In other words, does
 "{0:abc,def,ghi}".format(value)
mean
 # Assume value.__format__ will delegate properly, to
 # result1.__format__("def,ghi")
 #
 # There are some surprises when a trailing field size gets ignored by
 # value.__class__.
 #
 # Are infinite loops more likely?
 value.__format__("abc,def,ghi")
or
 # The separator character (","?) gets hard to use in format strings...
 value.__format__("abc").__format__("def").__format__("ghi")
-jJ


More information about the Python-3000 mailing list

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