On 5/23/2013 2:42 PM, Dave Angel wrote:
On 05/23/2013 11:26 AM, Carlos Nepomuceno wrote:
eggs(a,f)
Traceback (most recent call last):
File "<pyshell#29>", line 1, in <module>
eggs(a,f)
File "<pyshell#1>", line 1, in eggs
def eggs(spam, ham): return spam % ham
TypeError: not all arguments converted during string formatting
'%s'%(5%3)
'2'
So % doesn't handle tuples! Why's that? Is it intentional (by design)?
It's a conflict in the design. A tuple is used to supply multiple
arguments to the % operator. So if you want to have a tuple as the
first argument, you need to enclose it in another tuple.
The problem is that interpolating 1 to many items into a string is *not*
a binary operation. The needed hack to pretend that it is, using a tuple
to represent multiple items rather than just itself, was one of the
reasons for making string formatting a honest function, where multiple
items to be formatted are passed as multiple arguments.
--
http://mail.python.org/mailman/listinfo/python-list