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

Posted 一叶知秋。

tags:

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

小记一下,今天使用open打开文件的时候出现了下面的错误。

注:我用的是Python3.6.1版本。

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

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

之前文件打开的语句是:

filehandle = open(WAV_FILE, ‘w‘)

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

filehandle = open(WAV_FILE, ‘wb+‘)

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

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