Python读取文件中的字符串已经是unicode编码,如:\u53eb\u6211,需要转换成中文时有两种方式

1.使用eval:

eval("u"+"\'"+unicodestr+"\'")

2.使用decode:

str1 = '\u4f60\u597d'
print str1.decode('unicode_escape')
你好

unicodestr.decode('unicode_escape')  # 将转义字符\u读取出来

# ’\u’开头就基本表明是跟unicode编码相关的,“\u”后的16进制字符串是相应汉字的utf-16编码。Python里decode()和encode()为我们提供了解码和编码的方法。其中decode('unicode_escape')能将此种字符串解码为unicode字符串。

Python 读取文件中unicode编码转成中文显示问题的更多相关文章

  1. jmeter响应信息unicode 编码转成中文

    在jmeter 发送请求过程中,有时候后台返回的是unicode 代码,如: {"status":-1,"msg":"\u63d0\u4ea4\u65 ...

  2. java 中文转换成Unicode编码和Unicode编码转换成中文

    转自:一叶飘舟 http://blog.csdn.net/jdsjlzx/article/details/ package lia.meetlucene; import java.io.IOExcep ...

  3. 把Java中\u格式的unicode编码转成中文

    使用org.apache.commons.lang.StringEscapeUtils#unescapeJava(String)方法. 当然用org.apache.commons.lang.Strin ...

  4. Java实现 中文转换成Unicode编码 和 Unicode编码转换成中文

    想要实现中文字符转换为Unicode编码的话主要用到的是一个这样的包,自己可以去API文档里面查看下的 java.util.Properties; 直接进入主题吧,主要是 package Test01 ...

  5. python读取文件中的字典

    import ast def file_read():    with open('D:\\pytharm\\jichuyufa\\day2\\pro_cty_con.txt', 'r', encod ...

  6. 利用Python从文件中读取字符串(解决乱码问题)

    首先声明这篇学习记录是基于python3的. python3中,py文件中默认的文件编码就是unicode,不用像python2中那样加u,比如u'中文'. 不过在涉及路径时,比如C:\Users\A ...

  7. json数据处理:读取文件中的json字符串,转为python字典

    方法1: 读取文件中的json字符串, 再用json.loads转为python字典 import json str_file = './960x540/config.json' with open( ...

  8. python操作txt文件中数据教程[3]-python读取文件夹中所有txt文件并将数据转为csv文件

    python操作txt文件中数据教程[3]-python读取文件夹中所有txt文件并将数据转为csv文件 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 python操作txt文件中 ...

  9. Python读取文件编码及内容

    Python读取文件编码及内容 最近做一个项目,需要读取文件内容,但是文件的编码方式有可能都不一样.有的使用GBK,有的使用UTF8.所以在不正确读取的时候会出现如下错误: UnicodeDecode ...

随机推荐

  1. canvas 实现贪吃蛇游戏

    var canvas = document.getElementById('canvas'); var cxt = canvas.getContext('2d'); // 定时器 var timer; ...

  2. 2019.01.13 loj#6515. 贪玩蓝月(线段树分治+01背包)

    传送门 题意简述:有一个初始为空的双端队列,每次可以在队首和队尾插入或弹出一个二元组(wi,vi)(w_i,v_i)(wi​,vi​),支持询问从当前队列中选取若干个元素是的他们的和对 MODMODM ...

  3. 2019.01.02 NOIP训练 三七二十一(生成函数)

    传送门 生成函数基础题. 题意简述:求由1,3,5,7,9这5个数字组成的n位数个数,要求其中3和7出现的次数都要是偶数. 考虑对于每个数字构造生成函数. 对于1,5,9:∑nxnn!=ex\sum_ ...

  4. B+树和LSM比较(转)

    出处:https://blog.csdn.net/u013928917/article/details/75912045 B+树和LSM比较 在关系型数据库mysql中普遍使用B+树作为索引,在实际中 ...

  5. best-case analysis in real-time system

    ECRTS: Exact Best-Case Response Time Analysis of Fixed Priority Scheduled Tasks motivation Real-time ...

  6. org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0

    Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/Ma ...

  7. 11-border(边框)

    边框 border:边框的意思,描述盒子的边框 边框有三个要素: 粗细 线性样式 颜色 border: solid 如果颜色不写,默认是黑色.如果粗细不写,不显示边框.如果只写线性样式,默认的有上下左 ...

  8. 1143 Lowest Common Ancestor

    The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U ...

  9. Application-identifier entitlement does not match问题的解决

    以下是一个老外的回答: This happened to me after installing a build from TestFlight and overwriting it with the ...

  10. 2018-04-11 activity周期

    android相机开发 1.Android wifi热点连接过程 2.bindservice和AIDLhttps://blog.csdn.net/zhou_wenchong/article/detai ...