Python如何时将部分utf8编码转义成中文内容,,现有1.txt文档,里面


现有1.txt文档,里面的内容是\xe6\x88\x90\xe9\x83\xbd

请问如何通过python读取这个文件的内容,然后显示成中文的形式?

为了让问题有趣一点,让我来一行代码搞定它 =w=

python2 -c 'import binascii as b; from sys import stdin, stdout; stdout.write(b.unhexlify(stdin.read().strip().replace("\\x", "")))'python3 -c 'import binascii as b; from sys import stdin, stdout; stdout.buffer.write(b.unhexlify(stdin.buffer.read().strip().replace(b"\\x", b"")))'ascii2uni -qa7

最后一行是赠品 =w=

import osf = open(r'2.txt').read().strip().replace("\\x","")print f.decode("hex")

在用Python2?换Python3吧。

Python2下:

print('\xe6\x88\x90\xe9\x83\xbd') ==> '成都'

编橙之家文章,

评论关闭