why 'double tuple' when using %s with print?
vr at acm.org
Thu Nov 9 18:22:00 CET 2000
* jkndeja at my-deja.com
> Hello there
> Here's a relatively simple question. If t is a tuple
> >>> t = (1,2)
> then I can print it with
> >>> print t
> to get the result. If I want to print is using the '%' operator,
> I try
> >>> print "my tuple is %s" % t
> but this gives me
> TypeError: not all arguments converted
> and I have to use
> >>> print "my tuple is %s" % (t,)
> to get what I expect.
> Shurely, since t is already a tuple, it shouldn't need to be converted
> into a 'tuple of tuples'?
the problem is exactly as Python reports: "not all arguments
converted". i.e. your tuple t consists of two values, but only one of
them is used in the print-statement.
>>> print "my tuple is %d %d" % t
my tuple is 1 2
hope-this-helps-ly y'rs, vr
More information about the Python-list