[Python-3000] String formating operations in python 3k

Georg Brandl g.brandl at gmx.net
Sun Apr 2 22:27:08 CEST 2006


Crutcher Dunnavant wrote:
> Python currently supports  'S % X', where S is a strinng, and X is one of:
> * a sequence
> * a map
> * treated as (X,)
> 
> But I have some questions about this for python 3000.
> 
> 1. Shouldn't there be a format method, like S.format(), or S.fmt()?

Possible, but why? "%" works quite fine. "Abusing" the modulus operator
is okay in this context since the symbol gives a nonoverseeable clue to
what the construct is doing.

> 2. What about using __call__ instead of / in addition to __rmod__?
> * "time: %s"(time.ctime()) == "time: %s" % time.ctime()
> * "%(a)s %(b)s"(a=1, b=2) == "%(a)s %(b)s" % {'a'=1, 'b'=2}

Damn ugly. How would you explain to a newbie that you can _call_ a string?
And that _calling_ a string does a formatting operation?
For me, string formatting with "%" is fine as it is.

BTW, has anyone seen string.Template being used somewhere?

Georg



More information about the Python-3000 mailing list