Naf*_*Kay 3 python unicode byte
我想将一个简单的Unicode字符串转储到一个字节数组中,所以我可以将每个字符串称为int.这可能吗?
我正在寻找一个字符串u"Hello World"并将其转换为UTF-8和类似的东西:`
[0x01, 0x02, ..., 0x02]
Run Code Online (Sandbox Code Playgroud)
我怎样才能有效地做到这一点?
Dav*_*son 10
如果您正在寻找Python bytearray:
my_array = bytearray(u"hello, world", encoding="utf-8")
Run Code Online (Sandbox Code Playgroud)
您的问题可能意味着两件事:使用UTF8编码Unicode字符串并获取结果字节的列表,或者获取Unicode代码点列表.
在前一种情况下:
list_of_bytes = map(ord, my_unicode_string.encode('utf8'))
Run Code Online (Sandbox Code Playgroud)
在后一种情况下:
list_of_code_points = map(ord, my_unicode_string)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2935 次 |
| 最近记录: |