码迷,mamicode.com
首页 > 编程语言 > 详细

Python_异常:TypeError: write() argument must be str, not list

时间:2018-10-04 14:56:02      阅读:6728      评论:0      收藏:0      [点我收藏+]

标签:写入内容   open   字符串   img   处理   原因   type   module   src   

文件写入操作时,报错:TypeError: write() argument must be str, not list

原因:python写入的内容要是字符串类型的

上代码:

fp = open("a.txt","w")
fp.write([1,2,3])
fp.close()

>>> fp = open("a.txt","w")
>>> fp.write([1,2,3])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: write() argument must be str, not list
>>> fp.close()

写入内容为字符串类型则ok

fp = open("a.txt","w")
fp.write([1,2,3])#将文件内容处理为字符串类型
fp.close()

技术分享图片

 

Python_异常:TypeError: write() argument must be str, not list

标签:写入内容   open   字符串   img   处理   原因   type   module   src   

原文地址:https://www.cnblogs.com/rychh/p/9742203.html

(3)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!