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. 谁说程序员不懂爱情【Her】

    2014.8.17日 我和我女朋友恋爱两周年的日子.走到今天很不容易,我很珍惜. 就想趁这机会,尽自己能力做一个特别的礼物. 这款应用两周前就开始计划了.也熬了几个晚上.接触wp开发时间不长,第一款应 ...

  2. C++中char类型的十六进制字符串转换成字节流

    如a[5]="1234"转换成a[5]={0x12,0x34} 代码如下: void HexStrToByte(const char* source, unsigned char* ...

  3. PHP 网站隔离配置

    PHP网站间隔离 网站内目录与目录之间是可以访问的,在某些特定情况下这样是不安全的,如果目录间网址权限被黑客利用很可能造成数据流失,在这里我们可以通过PHPopen_basedir来实现网站间目录隔离 ...

  4. python的正则表达式捕获组命名问题

  5. Tomcat:解决Tomcat可以在eclipse启动,却无法显示默认页面的操作

    解决Tomcat可以在eclipse启动,却无法显示默认页面的操作 今天在eclipse中配置好tomcat后访问不到它的主页,但是能运行自己的项目,一直找不到原因,百度之后最后解决了这个问题,总结如 ...

  6. 【Java并发】Executor框架

      Executor框架简介 Java的线程既是工作单元,也是执行机制.从JDK5开始,把工作单元和执行机制分离开来. Executor框架由3大部分组成 任务. 被执行任务需要实现的接口:Runna ...

  7. Python中的X[:,0]和X[:,1]

    https://blog.csdn.net/csj664103736/article/details/72828584 python中 x=x[1:] 是什么意思 将x的第二位到最后一位的内容赋给x. ...

  8. scala学习手记40 - case表达式里的模式变量和常量

    再来看一下之前的一段代码: def process(input: Any) { input match { case (a: Int, b: Int) => println("Proc ...

  9. 牛客练习赛13D

    定义一个数字为幸运数字当且仅当它的所有数位都是4或者7.比如说,47.744.4都是幸运数字而5.17.467都不是.现在想知道在1...n的第k小的排列(permutation,https://en ...

  10. Updated: EBS 12.1 + Transportable Tablespaces with Incremental Backup Option

    Database migration across platforms of different "endian" (byte ordering) formats using th ...