python写入文本报错TypeError: expected a string or other character buffer object
2017-05-07 15:42
2621 查看
今天用python写入文本,
报错 TypeError: expected a string or other character buffer object
原因:
是写入文件要求写入内容是str,直接转换成str即可,如下:
补充:
还有一个读操作的代码:
1 file_object2 = open('result.txt', 'w') 2 file_object2.write(bookid_list) 3 file_object2.close( )
报错 TypeError: expected a string or other character buffer object
原因:
是写入文件要求写入内容是str,直接转换成str即可,如下:
1 file_object2 = open('result.txt', 'w') 2 file_object2.write(str(bookid_list)) 3 file_object2.close()
补充:
还有一个读操作的代码:
1 file_object = open('thefile.txt') 2 try: 3 all_the_text = file_object.read( ) 4 finally: 5 file_object.close( )
相关文章推荐
- Python出现: TypeError: expected string or buffer
- html内容写入到文件中的时候出现‘TypeError: expected a character buffer object’错误
- django 接受post请求json.dumps()的时候会引发TypeError: 'expected string or buffer'错误
- TypeError: expected a character buffer object
- python smtplib TypeError: expected string or buffe
- Python TypeError: coercing to Unicode: need string or buffer, float found
- a=re.findall('b',c)报错提示:TypeError:expected string or buffer
- 解决:error: Cannot fetch repo (TypeError: expected string or buffer)
- TypeError: expected string or buffer
- Python TypeError: must be string or buffer, not dict
- ORA-06502:PL/SQL :numberic or value error: character string buffer too small
- ORA-06502:PL/SQL :numberic or value error: character string buffer too small
- [Python]json对象转换出错expected string or buffer python
- TypeError: expected dynamic type 'string', but had type 'object'
- python字符串和变量相加时出现,coercing to unicode need string or buffer nonetype found python 错误的解决
- python :TypeError: 'builtin_function_or_method' object has no attribute '__getitem__'
- ORA-06502: PL/SQL: numeric or value error: character string buffer too small
- python出现,coercing to unicode need string or buffer nonetype found python 错误的解决
- python3-网络编程-TypeError: send() argument 1 must be bytes or buffer, not str异常
- spark 报错ypeError: expected string or Unicode object, NoneType found