NOT Re: Bug in % string formatting?
Steven Majewski
sdm7g at Virginia.EDU
Thu Dec 20 16:10:31 EST 2001
On Thu, 20 Dec 2001, Fernando [ISO-8859-1] Pérez wrote:
> If this is not a bug in % string formatting, I'd love to understand what is
> going on.
>
> # but this fails. The format string is copied verbatim from above
> print 'Explicit list construction:'
> print format_string % names['John'][:] + names['Jane'][:]
Try wrapping the addition in parends:
>>> print format_string % ( names['John'][:] + names['Jane'][:])
John Doe <jodoe at nowhere>
Jane Doe <jadoe at nowhere>
Without explicit parends, you're doing the equivalent of:
>>> print (format_string % names['John'][:]) + names['Jane'][:]
Yes: it would make more sense if the order of operations were
different, but remember -- "%" and "+" both double as arithmetic
and string operators, but both cases have to share the same
preecedence.
-- Steve Majewski
More information about the Python-list
mailing list