On 05/23/2013 11:26 AM, Carlos Nepomuceno wrote:
----------------------------------------
Date: Thu, 23 May 2013 06:44:05 -0700
Subject: Re: PEP 378: Format Specifier for Thousands Separator
From: prueba...@latinmail.com
To: python-list@python.org
[...]
You left out the part where a and f are initialized:
>>> a='%s'
>>> f=(3,5)
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.
try the following:
print a % (f,)
The trouble is, it doesn't generalize very readily, so it's difficult to
use in a function like eggs()
--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list