1. 中文编码成16进制
>>> str1 = '你好,世界!'
>>> str1.encode('unicode_escape')
b'\\u4f60\\u597d\\uff0c\\u4e16\\u754c\\uff01'
2. 16进制解码成中文
>>> str2 = '\u4f60\u597d\uff0c\u4e16\u754c\uff01'
# Python2.7
>>> str2.decode("unicode_escape").encode("utf-8")
# python3.6
>>> str2.encode('utf-8').decode('utf-8')
# 因版本问题会有差异
'你好,世界!'