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的更多相关文章

  1. Python 读写文件 中文乱码 错误TypeError: write() argument must be str, not bytes+

    今天写上传文件代码,如下 def uploadHandle(request): pic1=request.FILES['pic1'] picName=os.path.join(settings.MED ...

  2. TypeError: write() argument must be str, not bytes报错

    TypeError: write() argument must be str, not bytes 之前文件打开的语句是: with open('C:/result.pk','w') as fp: ...

  3. TypeError: write() argument must be str, not bytes报错原因及Python3写入二进制文件方法

    Python2随机写入二进制文件: with open('/python2/random.bin','w') as f: f.write(os.urandom(10)) 但使用Python3会报错: ...

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

    w文件打开以 '二进制'  方式: with open('teacher.html','wb+') as f: f.write(response.body) 要写入"中文",防止乱 ...

  5. 问题记录2:TypeError: write() argument must be str, not bytes

    今天试了下用requests模块的get()方法来下载图片,写入文件的时候不能写入二进制,然后将打开方式改成二进制的就好了. 原因是,f.content的存储方式是二进制,而文件正常打开默认是字符串的 ...

  6. python write() argument must be str, not bytes

    python pickle from __future__ import absolute_import from __future__ import division from __future__ ...

  7. Python - TypeError: unicode argument expected, got 'str'

    参考:TypeError: unicode argument expected, got 'str' Python代码: from io import StringIO def main(): f = ...

  8. Python2.7 在使用BSTestRunner.py时报错TypeError: unicode argument expected, got 'str'

    python3往这个库中加入了一些新的内容,使得该库在Python2.7中报错. 解决方法是将导入语句 from io import StringIO as StringIO 更换为: from io ...

  9. Python中的编码问题(encoding与decode、str与bytes)

    1 引言 在文件读写及字符操作时,我们经常会出现下面这几种错误: TypeError: write() argument must be str, not bytes AttributeError: ...

随机推荐

  1. Saltstack sls文件:批量安装服务

    一.使用saltstack 批量安装nginx 1.创建salt目录 mkdir /srv/{salt,pillar} 2.再/srv/salt/下创建sls文件 vim nginx_install. ...

  2. 服务端Job调度程序

    GIT地址:https://github.com/youbl/PlanServer

  3. 在react-native中使用redux

    redux是什么? redux是一个用于管理js应用状态的容器.redux出现时间并不是很长,在它出现之前也有类似功能的模块出现,诸如flux等等.redux设计的理念很简单,似乎最初这个开发团队就有 ...

  4. Execute Disable Bit

    “Execute Disable Bit”是Intel在新一代处理器中引入的一项功能,开启该功能后,可以防止病毒.蠕虫.木马等程序利用溢出.无限扩大等手法去破坏系统内存并取得系统的控制权.其工作原理是 ...

  5. jq限制字符个数

    <script> $(document).ready(function () { //限制字符个数 $(".box-right .title a").each(func ...

  6. Hibernate的一级缓存、二级缓存和查询缓存。

    Hibernate的Session提供了一级缓存的功能,默认总是有效的,当应用程序保存持久化实体.修改持久化实体时,Session并不会立即把这种改变提交到数据库,而是缓存在当前的Session中,除 ...

  7. MySQL explain 、explain extended用法

    explain显示了mysql如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句. 使用方法,在select语句前加上explain就可以了,如: explai ...

  8. Java Collections Framework Java集合框架概览

    Java SE documents -- The Collections Framework http://docs.oracle.com/javase/8/docs/technotes/guides ...

  9. Hibernate -- 映射多对多双向关联关系

    1. 示例代码: Student.java package cn.itcast.many2many; import java.util.HashSet; import java.util.Set; @ ...

  10. Delphi_时间间隔

    1. var dtOnlineDateTime, dt: TDateTime; begin dt := StrToDateTime('2017/6/28 16:41:30'); dtOnlineDat ...