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: ...
随机推荐
- GIT使用—创建一个版本库
一.GIT命令行 [root@localhost ~]# git usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path] ...
- 关于div可编辑的复制粘贴问题
todoFilter(e) { e.preventDefault(); if (!e.target.getAttribute('contenteditable')) { return; } const ...
- 启动工程Ehcache报错
缓存组建用的Ehcache,在启动的时候报了下面的错误,虽然不影响使用,看着还是有点碍眼: DEBUG net.sf.ehcache.util.UpdateChecker - Update che ...
- Makefile文件应用——simple项目
学习资料 本文主要参考资料:驾驭Makefile(李云).pdf 原理 (1)最基本的语法 targets: prerequisites command targets是目标,prerequisite ...
- Java控制语句——分支、循环、跳转
分支语句(if语句,switch语句): 循环语句(for,while,do...while); 跳转语句(break,continue,return): 分支语句(if语句,switch语句) if ...
- bat脚本——删除当前文件夹的所有指定文件类型
学了这个,就不用手动删除大量的指定的文件类型,可以做到双击bat处理文件就可以删除了 比如说,我要删除当前文件夹下的txt文件和doc文件,代码如下 del *.txt* del *.doc* 其原理 ...
- 使用mysqldump迁移数据
1. 先停止业务,使用MySQLdump的数据导出工具,将您线下原有数据库数据导出为数据文件 mysqldump -hlocalhost -uroot --default-character-set= ...
- I方法怎么不能获取多选框的数据
前端代码 <input type="checkbox" name="m_name" value="{$vo.name}" class ...
- NumPy数学算数函数
NumPy - 算数函数 很容易理解的是,NumPy 包含大量的各种数学运算功能. NumPy 提供标准的三角函数,算术运算的函数,复数处理函数等. 三角函数 NumPy 拥有标准的三角函数,它为弧度 ...
- EditText实现输入表情
EditText实现输入表情 一.简介 editText是TextView的子类,TextView能用的工具EditText都能用,这里就是editText利用SpannableString的Imag ...