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?
Thanks,
Jeremy 6 2437
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
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?
Thanks,
Jeremy
Try
print "a = %s" % (a, )
The exception to the "a single object can be formatted as a single
argument rather than a tuple" rule is when that single object is itself
a tuple!
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
Tim Chase wrote:
print "a = %s" % repr(a)
or
print "a = %r" % (a,)
In <11*********************@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
>>>>"Tim" == Tim Chase <py*********@tim.thechases.comwrites:
>How can I print a tuple with a single string format?
Tim print "a = %s" % str(a)
Timor
Tim print "a = %s" % repr(a)
Or wrap the tuple in a tuple:
print "a = %s" % (a,)
Skip sk**@pobox.com wrote:
>>>"Tim" == Tim Chase <py*********@tim.thechases.comwrites:
>How can I print a tuple with a single string format?
Tim print "a = %s" % str(a)
Timor
Tim print "a = %s" % repr(a)
Or wrap the tuple in a tuple:
print "a = %s" % (a,)
Skip
Thank you all very much for your help.
Jeremy This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Chrigel |
last post by:
Hi all,
We have problems deseralizing objects previously serialized as XML.
This did work fine with .NET 1.1 but since we have installed SP1,
deserializing fails (but serializing works). The...
|
by: Marco Herrn |
last post by:
Hi,
I need to serialize an object into a string representation to store it
into a database. So the SOAPFormatter seems to be the right formatter
for this purpose. Now I have the problem that...
|
by: ilona |
last post by:
Hi all,
I store phone numbers in the database as 123447775665554(input mask is used
for input, and some numbers have extensions), and I also know from db if the
number is Canadian, US, or some...
|
by: Matt |
last post by:
I am attempting to reformat a string, inserting newlines before certain
phrases. For example, in formatting SQL, I want to start a new line at
each JOIN condition. Noting that strings are...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |