Python 根据 汉字的 unicode 编码(int类型)得到汉字字符?
1个回答
展开全部
def decimal2hex(number):
return hex(number)[2:]
def hex2unicode(hex_number_string):
return '\\u' + hex_number_string
def unicode2chinese(unicode_number):
if isinstance(unicode_number, str):
return unicode_number.encode("latin-1").decode("unicode-escape")
elif isinstance(unicode_number, bytes):
return unicode_number.decode("unicode-escape")
if __name__ == "__main__":
number = 39532
hex_number_string = decimal2hex(number)
unicode_number = hex2unicode(hex_number_string)
chinese = unicode2chinese(unicode_number)
print(chinese)
return hex(number)[2:]
def hex2unicode(hex_number_string):
return '\\u' + hex_number_string
def unicode2chinese(unicode_number):
if isinstance(unicode_number, str):
return unicode_number.encode("latin-1").decode("unicode-escape")
elif isinstance(unicode_number, bytes):
return unicode_number.decode("unicode-escape")
if __name__ == "__main__":
number = 39532
hex_number_string = decimal2hex(number)
unicode_number = hex2unicode(hex_number_string)
chinese = unicode2chinese(unicode_number)
print(chinese)
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询