UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 7: ordinal not in range(128) [duplicate]
Python在往文件里写东西的时候,如果ascii码报错
参考
http://stackoverflow.com/questions/19833440/unicodeencodeerror-ascii-codec-cant-encode-character-u-xe9-in-position-7
You need to encode Unicode explicitly before writing to a file, otherwise Python does it for you with the default ASCII codec.
Pick an encoding and stick with it:
f.write(printinfo.encode('utf8') + '\n')
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 7: ordinal not in range(128) [duplicate]的更多相关文章
- Windows下pip安装及更新出现“UnicodeEncodeError: 'ascii' codec can't encode character u'\u258c' in position 8: ordinal not in range(128)”问题解决办法
Windows下pip安装及更新出现“UnicodeEncodeError: 'ascii' codec can't encode character u'\u258c' in position 8: ...
- UnicodeEncodeError: 'ascii' codec can't encode character u'\u5929' in position 2: ordinal not in range(128)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u5929' in position 2: ordinal not in ran ...
- UnicodeEncodeError: 'ascii' codec can't encode character u'\u65e0' in position 1: ordinal not in range(128)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u65e0' in position 1: ordinal not in ran ...
- ERROR (UnicodeEncodeError): 'ascii' codec can't encode character u'\uff08' in position 9: ordinal not in range(128)
环境win10+anaconda2 在安装labelme时遇到了这个问题,其实跟labelme没啥关系,主要是python2读取中文路径时报错,因为默认编码是ASCII,不认识中文,看到有一个一次性解 ...
- 【Python】解决UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 0: ordinal not in range(128)
指定文件字符集为utf-8 在文件头部加入以下代码: import sys reload(sys) sys.setdefaultencoding('utf-8')
- UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\u8888′ in position 0: ordinal not in range(168)
python保存文件UnicodeEncodeError以及reload(sys)后print失效问题 在将字符串写入文件时,执行f.write(str),后台总是报错:UnicodeEncodeEr ...
- 数据库连接 UnicodeEncodeError: 'latin-1' codec can't encode character u'\u4eac' in position 0: ordinal not in range(256),UnicodeEncodeError: 'latin-1' codec can't encode character
处理方法就是,设置连接和游标的charset为你所希望的编码,如utf8, 连接数据库的时候加上 charset="utf8 db = MySQLdb.connect(host= '14 ...
- UnicodeEncodeError: 'ascii' codec can't encode character u'\u5728' in position 1
s = "图片picture"print chardet.detect(s) for c in s.decode('utf-8'): print c UnicodeEncodeEr ...
- 解决:"UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position"错误
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/Haiyang_Duan/article/ ...
随机推荐
- 【Raspberry pi】cpu、内存等查看及扩展
使用树莓派时,需要在其系统中部署几个不同功能的程序系统,并涉及到数据库读写.串口读写.web访问等,使系统使用压力较大,在查看树莓派使用情况时也遇到些许问题. free命令 total used fr ...
- 【Python MySQLdb】Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib解决办法
使用MySQLdb遇到以下错误 ImportError: dlopen(/Users/jackey/Documents/Xiaomi/Code/wda_python/lib/python2./site ...
- [感悟]马士兵Java自学之路——(精华版)
JAVA自学之路 一: 学会选择 为了就业,不少同学参加各种各样的培训. 决心做软件的,大多数人选的是java,或是.net,也有一些选择了手机.嵌入式.游戏.3G.测试等. 那么究竟应该选择什么方向 ...
- RabbitMQ(2) vhost、用户和权限
rabbitmq中,vhost提供了资源隔离机制.同时,通过为用户设置vhost粒度的权限,可以实现丰富的权限控制功能. vhost 在rabbitmq中,可以创建被称为虚拟主机(vhost)的虚拟消 ...
- COW写时复制
body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...
- 浅谈《剑指offer》原题:不使用条件、循环语句求1+2+……+n
转载自:浅谈<剑指offer>原题:求1+2+--+n 如侵犯您的版权,请联系:windeal12@qq.com <剑指offer>上的一道原题,求1+2+--+n,要求不能使 ...
- APUE学习笔记——10.9 信号发送函数kill、 raise、alarm、pause
转载注明出处:Windeal学习笔记 kil和raise kill()用来向进程或进程组发送信号 raise()用来向自身进程发送信号. #include <signal.h> int k ...
- c# DataTable 导出csv文件
using System; using System.Data; using System.Configuration; using System.Collections.Generic; using ...
- obj-y,obj-m 区别
obj-y:把由foo.c 或者 foo.s 文件编译得到foo.o 并连接进内核.obj-m: 则表示该文件作为模块编译.除了y.m以外的obj-x 形式的目标都不会被编译. 除了obj-形式的目标 ...
- C++解决error C4996报错
今天用c++写了个数独程序,在编译过程中报了一个错误: 1>------ 已启动生成: 项目: sudoku, 配置: Debug Win32 ------1> main.cpp1> ...