New-style string formatting

Mel Wilson mwilson at the-wire.com
Tue May 20 15:44:51 EDT 2003


In article <mailman.1053447752.25340.python-list at python.org>,
Skip Montanaro <skip at pobox.com> wrote:
>    Gerrit> What Alexander proposes and I support is not to do string
>    Gerrit> interpolation, but to simply change the syntax because the '%'
>    Gerrit> is redundant; it's a much smaller change:
>    Gerrit> "bla %s blo %d" % ("blu", 42) # becomes
>    Gerrit> "bla %s blo %d" ("blu", 42)

>Just because it's not a big change doesn't mean it's worthwhile.  Here are
>a couple counterarguments: [ ... ]
>    * This idea doesn't extend to dictionary interpolation (without a change
>      to the language syntax), which for interpolations with many arguments
>      is less error-prone because you specifically indicate what value to
>      insert where instead of relying on positional correctness.

   Actually, it probably would, via

        "%d %g %r%s" (*list_of_things())
and
        "%(a1)d %(a2)g %(a3)r%(a4)s" (**some_dictionary)

   but I still don't like it enough, for the other reasons
you give, and the fact that it pre-empts callability for any
user-defined string-like object.  One way to do the same thing
means that class authors only have to implement those one ways
to have done Right by the standard implementation.

        Regards.        Mel.




More information about the Python-list mailing list