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

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

 

上代码:

>>> fp = open("a.txt","rb+",encoding="utf-8")#rb+操作时不支持指定encoding参数

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

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

 

解决:

改成如下方法即可

>>> fp = open("a.txt","rb+")#注意:a.txt文件编码格式需为“ANSI”
>>> fp.close()

相关文章:

  • 2021-11-22
  • 2022-02-14
  • 2021-09-26
  • 2022-12-23
  • 2021-08-16
  • 2021-07-23
  • 2021-09-23
  • 2022-12-23
猜你喜欢
  • 2021-06-16
  • 2022-01-31
  • 2021-12-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案