
python 3 执行脚本时报错“typeerror:string formatting 中未转换所有参数”
在执行 python 3 脚本时,遇到了如下报错:
traceback (most recent call last):
file "test.py", line 97, in <module>
out_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() 方法。
以上就是Python 3 脚本报错“TypeError:string formatting 中未转换所有参数”如何解决?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号