Python 文件操作Error: binary mode doesn't take an encoding argument


Python 报错:ValueError: binary mode doesn't take an encoding argument

    在运行文件操作相关功能时报错:ValueError: binary mode doesn't take an encoding argument

 

上代码:

>>> with open("course_info","rb+",encoding="utf-8")as f: #rb+操作时不支持指定encoding参数

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: binary mode doesn't take an encoding argument

原因分析:rb+操作时不支持指定encoding参数

解决办法: 去掉encoding,改成 with open('course_info','rb+') as f:


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM