str = u'上海'
uni = str.encode('unicode-escape')
uni
Out[55]: b'\\u4e0a\\u6d77'
uni.decode()
Out[56]: '\\u4e0a\\u6d77'
print(uni)
b'\\u4e0a\\u6d77'
str = '\\u6bd5\\u8282\\u5730\\u533a'
str.encode('utf-8').decode('unicode_escape')
str = u'上海'
uni = str.encode('unicode-escape')
uni
Out[55]: b'\\u4e0a\\u6d77'
uni.decode()
Out[56]: '\\u4e0a\\u6d77'
print(uni)
b'\\u4e0a\\u6d77'
str = '\\u6bd5\\u8282\\u5730\\u533a'
str.encode('utf-8').decode('unicode_escape')