string formatter for tuple
Tim Chase
python.list at tim.thechases.com
Thu Nov 2 10:44:47 EST 2006
> 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?
You can try
print "a = %s" % str(a)
or
print "a = %s" % repr(a)
which should both do the trick.
-tkc
More information about the Python-list
mailing list