
python 3 执行脚本时报错“typeerror:string formatting 中未转换所有参数”
在执行 python 3 脚本时,遇到了如下报错:
traceback (most recent call last): file "test.py", line 97, inout_tgt.write('%s\n' % rows) typeerror: not all arguments converted during string formatting
问题代码如下:
for i in range(1, 10):
out_tgt.write('%s\n' % rows)要解决此问题,应将字符串格式化语法修改为:
立即学习“Python免费学习笔记(深入)”;
for i in range(1, 10):
out_tgt.write('%s\n' % (rows,))修改后,脚本将成功执行,因为 % 运算符现在将 rows 转换为一个元组,并将其作为单个参数传递给 write() 方法。










