python中TypeError: not all arguments converted during string formatting解决方法
例如:
>>> str=(1,2,3) #创建一个集合
>>> str
(1, 2, 3)
>>> print 'str= %s ' % str
Traceback (most recent call last):
File "<pyshell#43>", line 1, in <module>
print 'str= %s ' % str
TypeError: not all arguments converted during string formatting
原因: % 操作符只能直接用于字符串('123'),列表([1,2,3])、元组
解决方法:
>>> print 'str= %s' % (str,)
str= (1, 2, 3)
也可以用:
>>> print 'str= %s,%s,%s' % str
str= 1,2,3
例如:
>>> str=(1,2,3) #创建一个集合
>>> str
(1, 2, 3)
>>> print 'str= %s ' % str
Traceback (most recent call last):
File "<pyshell#43>", line 1, in <module>
print 'str= %s ' % str
TypeError: not all arguments converted during string formatting
原因: % 操作符只能直接用于字符串('123'),列表([1,2,3])、元组
解决方法:
>>> print 'str= %s' % (str,)
str= (1, 2, 3)
也可以用:
>>> print 'str= %s,%s,%s' % str
str= 1,2,3