Bug or intended behavior?

Peter Pearson pkpearson at nowhere.invalid
Wed Jun 7 12:27:55 EDT 2017


On Tue, 6 Jun 2017 13:16:00 -0400, Terry Reedy <tjreedy at udel.edu> wrote:
> On 6/5/2017 1:01 PM, Peter Pearson wrote:
>> On Fri, 2 Jun 2017 10:17:05 -0700 (PDT), sean.dizazzo at gmail.com wrote:
>> [snip]
>>>>>> print "foo %s" % 1-2
>>> Traceback (most recent call last):
>>>    File "<stdin>", line 1, in <module>
>>> TypeError: unsupported operand type(s) for -: 'str' and 'int'
>> 
>> Others have already pointed out that you're assuming the
>> wrong precedence:
>> 
>> Say
>>      "foo %s" % (1-2)
>> not
>>      ("foo %s" % 1) - 2
>> .
>> 
>> Personally I prefer a less compact but more explicit alternative:
>> 
>>      "foo {}".format(1-2)
>
> More compact:
> >>> f'foo {1-2}'
> 'foo -1'

Sarcastic thanks, dude.  Excuse me while I scrub my screen with Clorox.
Or maybe my eyeballs.

More seriously, I thought "format" was the Cool New Thing toward which
all the cool kids were moving.  But here I tried to be cool and put in a
plug for "format", and the hip community seems to be sticking up for
"%".  Can I never get with the times?

-- 
To email me, substitute nowhere->runbox, invalid->com.



More information about the Python-list mailing list