[Python] TypeError: write() argument must be str, not bytes
程序员文章站
2024-02-21 23:17:28
...
问题:
今天使用Python向文件中写入内容报了如下错误:
TypeError: write() argument must be str, not bytes
解决:
原因是文件打开方式有问题,把之前的打开语句修改为二进制方式打开就没有问题了。如下:
修改前的语句:
f_w = open(file_name, "w")
修改后的语句:
f_w = open(file_name, "wb+")
推荐阅读
-
python write() argument must be str, not bytes
-
TypeError: write() argument must be str, not bytes
-
TypeError: write() argument must be str, not bytes
-
[Python] TypeError: write() argument must be str, not bytes
-
pytorch gpu版本安装外部库报错 TypeError: LoadLibrary() argument 1 must be str, not None
-
解决报错:TypeError: argument should be integer or bytes-like object, not ‘str‘
-
TypeError: join() argument must be str or bytes, not ‘PosixPath‘
-
编译安卓源码提示:TypeError: argument should be integer or bytes-like object, not ‘str‘
-
TypeError: the JSON object must be str, bytes or bytearray, not NoneType
-
TypeError: write() argument must be str, not bytes报错