Bug in % string formatting?

Justin Sheehy justin at iago.org
Fri Dec 21 12:06:01 EST 2001


Fernando Pérez <fperez528 at yahoo.com> writes:

>> Operator precedence :-), change it to
>>>>> print format_string % (names['John'][:] + names['Jane'][:] )
>> 
>
> Argggh! As they say in numerical recipes: you should brush your teeth every 
> night in front of the operator precedence rules for your language of choice.

There's a much simpler rule to follow:  Parenthesize.

Whenever you're not absolutely sure of precedence (and sometimes when
you are) parenthesize your expressions for explicit grouping.  If you
get into this habit, you don't end up being bitten by precedence.

-Justin

 





More information about the Python-list mailing list