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的更多相关文章
- Python 读写文件 中文乱码 错误TypeError: write() argument must be str, not bytes+
今天写上传文件代码,如下 def uploadHandle(request): pic1=request.FILES['pic1'] picName=os.path.join(settings.MED ...
- TypeError: write() argument must be str, not bytes报错
TypeError: write() argument must be str, not bytes 之前文件打开的语句是: with open('C:/result.pk','w') as fp: ...
- TypeError: write() argument must be str, not bytes报错原因及Python3写入二进制文件方法
Python2随机写入二进制文件: with open('/python2/random.bin','w') as f: f.write(os.urandom(10)) 但使用Python3会报错: ...
- TypeError: write() argument must be str, not bytes
w文件打开以 '二进制' 方式: with open('teacher.html','wb+') as f: f.write(response.body) 要写入"中文",防止乱 ...
- 问题记录2:TypeError: write() argument must be str, not bytes
今天试了下用requests模块的get()方法来下载图片,写入文件的时候不能写入二进制,然后将打开方式改成二进制的就好了. 原因是,f.content的存储方式是二进制,而文件正常打开默认是字符串的 ...
- python write() argument must be str, not bytes
python pickle from __future__ import absolute_import from __future__ import division from __future__ ...
- Python - TypeError: unicode argument expected, got 'str'
参考:TypeError: unicode argument expected, got 'str' Python代码: from io import StringIO def main(): f = ...
- Python2.7 在使用BSTestRunner.py时报错TypeError: unicode argument expected, got 'str'
python3往这个库中加入了一些新的内容,使得该库在Python2.7中报错. 解决方法是将导入语句 from io import StringIO as StringIO 更换为: from io ...
- Python中的编码问题(encoding与decode、str与bytes)
1 引言 在文件读写及字符操作时,我们经常会出现下面这几种错误: TypeError: write() argument must be str, not bytes AttributeError: ...
随机推荐
- Python3.x:百分比数转小数
Python3.x:百分比数转小数 def change_percent(num): zfflag = "" if "+" in num: num = num. ...
- 介绍Web项目中用到的几款JS日历日期控件和JS文本编辑框插件
第一款日历日期控件:layDate 官方网站:http://laydate.layui.com/ 第二款日历日期控件:my97 官方网站:http://www.my97.net/ 第三款 文本编辑器控 ...
- kali安装后配置
0x00.安装Vmware Tools 由于是在VMware Workstation里面安装的,所以需要首先安装VMware tools工具方便我们Ctrl+C和Ctrl+V,步骤如下: 在VMWar ...
- 检索并打印一个DNS主机条目
检索并打印一个DNS主机条目的 C 程序 --- Linux/Unix /*************************************************************** ...
- JavaWeb Listener
1. 监听器概述 1.1. 什么是监听器 做过Swing或者AWT图像界面Java程序开发的话,应该对Listener与Event非常熟悉.Swing或者AWT中通过Listener与Event来处理 ...
- ubuntu16.04的anacoda内置的spyder不支持中文【学习笔记】
执行下面的语句:将libfcitxplatforminputcontextplugin.so复制到anaconda2的安装目录下的platforminputcontexts目录重启生效 cp /usr ...
- MYSQL的基本语句——思维导图
如图 思维导图图片链接 http://www.edrawsoft.cn/viewer/public/s/a1718332616630 有道云笔记图片链接 http://note.youdao.com/ ...
- 在OpenStack里怎样配置Neutron,让虚拟机访问外网
http://blog.csdn.net/zhangli_perdue/article/details/50264681 OpenStack里虚机(或者叫instance)只有在分配floating ...
- v-model和sync修饰符
场景: 在用vue开发的过程中我们经常会遇到父子组件共用同一变量的情况,那么在这种情况下,我们肯定会想直接 把变量传过来用,因为是双向绑定的所以子组件就会修改这个变量,这样在vue中时会报错的. 问题 ...
- springboot打Jar包和War包
一:打JAR包 在工程的pom.xml中添加以下依赖 <build> <plugins> <plugin> <groupId>org.springfra ...