python写入文本报错TypeError: expected a string or other character buffer object
今天用python写入文本,
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( )
没有学不会的程序员,只有不努力的程序员。
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 智能桌面机器人:用.NET IoT库控制舵机并多方法播放表情
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 开发者新选择:用DeepSeek实现Cursor级智能编程的免费方案
· Tinyfox 发生重大改版
· 独立开发经验谈:如何通过 Docker 让潜在客户快速体验你的系统
· 小米CR6606,CR6608,CR6609 启用SSH和刷入OpenWRT 23.05.5
· 近期最值得关注的AI技术报告与Agent综述!