python utf-8 转码问题

print str('\345\207\235\346\266\265\346\237\217').decode('string_escape')
凝涵柏

但该语句在python3中无法运行

File "script.py", line 3
print str('\345\207\235\346\266\265\346\237\217').decode('string_escape')
^
SyntaxError: invalid syntax

Exited with error status 1

解决办法:

print (str('\345\207\235\346\266\265\346\237\217').encode('latin1').decode('unicode-escape').encode('latin1').decode('utf-8'))

凝涵柏

 

posted on 2020-11-20 22:59  那年月光  阅读(512)  评论(0编辑  收藏  举报