A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2009-October/092501.html below:

[Python-Dev] transitioning from % to {} formatting

[Python-Dev] transitioning from % to {} formattingNick Coghlan ncoghlan at gmail.com
Sat Oct 3 07:19:55 CEST 2009
Steven Bethard wrote:
> On Fri, Oct 2, 2009 at 12:43 PM, Martin Geisler <mg at lazybytes.net> wrote:
>> I hate calling methods on string literals, I think it looks very odd to
>> have code like this:
>>
>>  "Displaying {0} of {1} revisions".format(x, y)
>>
>> Will we be able to write this as
>>
>>  "Displaying {0} of {1} revisions" % (x, y)
>>
>> too?
> 
> I doubt it. One of the major complaints about the %-style formatting
> was that the use of % produced (somewhat) unexpected errors because of
> how operator precedence works::
> 
>>>> '{0}'.format(4 + 1)
> '5'
>>>> '%s' % 4 + 1
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: cannot concatenate 'str' and 'int' objects
> 
> Steve

The other major problem with the use of the mod operator is the bugs
encountered with "fmt % obj" when obj happened to be a tuple or a dict.

So no, the switch to a method rather than an operator was deliberate.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4