>>> print "my name is %s" %('foo','bar')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during string formatting
It means I have 2 values to replace ('foo', 'bar') but only provided one place holder (%s).
To correct it
>>> print "my name is %s %s" %('foo','bar')
my name is foo bar
There is also a another way to achieve this using str.format().
>>> print "my name is {0} {1}".format('foo','bar')
my name is foo bar
0
Hassek
On
There is another option with dictionaries
mydict = {'foo': 'bar', 'foo2': 'bar2'}
print "my name is %(foo)s" % mydict
this way you can use only foo if you want.
Note the last 's' is for 'string', so if you add something like %(foo)d it means %d with name foo.
The error you mentioned arise in cases like
It means I have 2 values to replace
('foo', 'bar')but only providedoneplace holder(%s).To correct it
There is also a another way to achieve this using str.format().