Death to tuples!

bonono at gmail.com bonono at gmail.com
Tue Nov 29 08:04:24 CET 2005


Rikard Bosnjakovic wrote:
> Steven Bethard wrote:
>
> > [1]http://www.python.org/dev/summary/2005-09-01_2005-09-15.html#string-formatting-in-python-3-0
>
> Reading this link, I find this:
>
> "Currently, using % for string formatting has a number of inconvenient
> consequences:
>
>      * precedence issues: "a%sa" % "b"*4 produces 'abaabaabaaba', not
> 'abbbba' " [...]
>
>
> Testing it locally:
>
>  >>> "a%sa" % "b"*4
> 'abaabaabaaba'
>
> But "b"*4 is not a tuple, as the formatting arguments are supposed to be,
> so why blame its erronious behaviour?
>
> Works fine this way:
>
>  >>> "a%sa" % ("b"*4,)
> 'abbbba'
>
> So I really do not see the problem. For my own format-strings, I always
> add a final comma to make sure it's a tuple I'm using.
>
> Just my $0.02.
>
this doesn't look like a tuple issue, but precedence of the operator.

"a%sa" % ("b"*4) 

also gives the expected answer. "abbbba"




More information about the Python-list mailing list