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-June/090160.html below:

[Python-Dev] Binary Operator for New-Style String Formatting

[Python-Dev] Binary Operator for New-Style String FormattingSteven Bethard steven.bethard at gmail.com
Sun Jun 21 20:08:42 CEST 2009
On Sun, Jun 21, 2009 at 1:36 PM, Jerry Chen<j at 3rdengine.com> wrote:
> QUICK EXAMPLES
>
>    >>> "{} {} {}" @ (1, 2, 3)
>    '1 2 3'
>
>    >>> "foo {qux} baz" @ {"qux": "bar"}
>    'foo bar baz'
>
> One of the main complaints of a binary operator in PEP 3101 was the
> inability to mix named and unnamed arguments:
>
>    The current practice is to use either a dictionary or a tuple as
>    the second argument, but as many people have commented ... this
>    lacks flexibility.

The other reason an operator was a pain is the order of operations:

>>> '{0}'.format(1 + 2)
'3'
>>> '%s' % 1 + 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'int' objects

In general, I don't see any gain in introducing an operator for string
formatting. What's the point? Maybe you save a few characters of
typing, but it sure is easier to Google for "Python string format"
than for "Python @".

A big -1 from me.

Steve
-- 
Where did you get the preposterous hypothesis?
Did Steve tell you that?
        --- The Hiphopopotamus
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