Python错误TypeError: write() argument must be str, not bytes

Posted cos1eqlg0

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python错误TypeError: write() argument must be str, not bytes相关的知识,希望对你有一定的参考价值。

2016-07-03 20:51:25

今天使用Python中的pickle存储的时候出现了以下错误:

TypeError: write() argument must be str, not bytes

网上搜索才发现原来是文件打开的方式有问题。

之前文件打开的语句是:

f=open("list.pkl","w+")

然后使用二进制方式打开就没有这个问题:

f=open("list_account.pkl","wb+")

产生问题的原因是因为pickle存储方式默认是二进制方式

以上是关于Python错误TypeError: write() argument must be str, not bytes的主要内容,如果未能解决你的问题,请参考以下文章