Python_報錯:ValueError: 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

 

上代碼:

>>> 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()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM