Python以不同的编码获取字符代码? [英] Python get character code in different encoding?
本文介绍了Python以不同的编码获取字符代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案方案
UTF-8是一个可变长度编码,所以我假设你真的意味着Unicode代码点。使用 chr()
将字符代码转换为字符,对其进行解码,并使用 ord()
获取代码点。
>>> ord(chr(145).decode('koi8-r'))
9618
Given a character code as integer number in one encoding, how can you get the character code in, say, utf-8 and again as integer?
解决方案
UTF-8 is a variable-length encoding, so I'll assume you really meant "Unicode code point". Use chr()
to convert the character code to a character, decode it, and use ord()
to get the code point.
>>> ord(chr(145).decode('koi8-r'))
9618
这篇关于Python以不同的编码获取字符代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文