![](/img/trans.png)
[英]Python - TypeError: write() argument must be str, not bytes
[英]TypeError: write() argument must be str, not dict (Python)
我正在开发一个在 txt 文件中显示我的信息的项目,它与 print 完美配合,但是当我尝试使用 write 时,它给了我以下错误:
TypeError: write() 参数必须是 str,而不是 dict
这是我的代码:
for x in range(len(list)):
outfile = open('message.txt', 'w')
outfile.write(list[x])
outfile.close()
您不能将字典写入字符串。 使用print(file=file_object)
或file.write(str())
。
代码:
for x in range(len(input_list)):
outfile = open('message.txt', 'w')
print(input_list[x], file=outfile)
outfile.close()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.