python库制作并获取utf8中unicode编码点。
utf8_codepoint的Python项目详细描述
python library生成并获取utf8中unicode代码点的编码。
编码utf8的规则表
设计utf-8可以在下表中看到 由dave prosser提出,随后由ken thompson修改。
Bit Code Point | The first code point | The last code point | Byte in Squence |
7 | U+0000 | U+007F | 1 |
11 | U+0080 | U+07FF | 2 |
16 | U+0800 | U+FFFF | 3 |
21 | U+10000 | U+1FFFFF | 4 |
26 | U+200000 | U+3FFFFFF | 5 |
31 | U+4000000 | U+7FFFFFFF | 6 |
您可以在a link中阅读上表中的更多内容。
安装
pip install utf8_codepoint
记录并贡献
github中的更多文档。
示例
使用此包的简单示例。
快速入门
fromutf8_codepointimportCodePoint# unicode symbol for European currencyeuro_money="U+20AC"# create instance objectcp=CodePoint(euro_money)# get representation integer of the Unicode Code Pointprint(cp.to_int())
结果是:
226 130 172
转换为十六进制表示形式
fromutf8_codepointimportCodePoint...print(cp.to_hex())
结果是:
E2 82 AC
到具有二进制表示的字符串
fromutf8_codepointimportCodePoint...print(cp.to_string())
结果是:
11100010 10000010 10101100
到二进制字符串表示的列表
fromutf8_codepointimportCodePoint...print(cp.to_list())
结果是:
['11100010', '10000010', '10101100']
以优美的风格显示所有数据
结果是: 获取所有数据 结果是: 如果要将其转换为json格式,可以传递
将真值作为get all方法中的参数:fromutf8_codepointimportCodePoint...cp.bprint()
{'0x20AC': {'bit_list': ['11100010', '10000010', '10101100'],
'code_point': 16,
'hexa_list': ['0xe2', '0x82', '0xac'],
'initial_bit': '1110',
'integer_list': [226, 130, 172]}}
fromutf8_codepointimportCodePoint...print(cp.get_all())
{'0x20AC':
{
'bit_list': ['11100010', '10000010', '10101100'],
'integer_list': [226, 130, 172],
'initial_bit': '1110',
'hexa_list': ['0xe2', '0x82', '0xac'],
'code_point': 16
}
}
cp.get_all(True)