[Python-3000] String formating operations in python 3k
walter at livinglogic.de
Mon Apr 3 01:48:40 CEST 2006
Crutcher Dunnavant wrote:
> On 4/2/06, Georg Brandl <g.brandl at gmx.net> wrote:
>> 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.
> Why? Because:
> 1 It is trivially cheap, format() would be the same function as __rmod__
> 2 It adds consistency with lower(), strip(), and other methods which
> produce new strings.
> 3 I am not arguing _against_ syntactic support, I am arguing _for_ a method;
> we can keep the syntactic support.
and it avoids one problem you might run into with %: If you have only
one argument, writing ``s % (x,)`` as ``s % x`` will break when the
argument x happens to be a tuple. You won't have this problem with
More information about the Python-3000