string formatter for tuple
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Thu Nov 2 10:37:53 EST 2006
In <1162481557.791817.41690 at b28g2000cwb.googlegroups.com>, jeremito wrote:
> I have the following in my code
>
> a = (1,2,3)
> print "a = %s" %a
>
> But when I run this, I get:
>
> TypeError: not all arguments converted during string formatting
>
> Now I realize why this happens, a is actually 3 elements when the print
> statement is only expecting to print one value. I tried
>
> print "a = %s" %(a)
>
> but I got the same error.
>
> How can I print a tuple with a single string format?
Put the tuple in a tuple:
print 'a = %s" % (a,)
And remember: not the parenthesis create a tuple but the comma!
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list