Nik*_*ika 1 python unicode ascii ord cyrillic
ord() 返回unicode代码,我需要ascii.
>>> s = "???" #cyrillic
>>> for char in s:
... print(ord(char))
...
1049 #unicode
1086 #unicode
1075 #unicode
Run Code Online (Sandbox Code Playgroud)
我需要ASCII.怎么弄?(下面)
你不能; ASCII中没有西里尔字符.您显示的图表是许多"扩展ASCII"字符集之一; 具体来说,它似乎是Windows-1251(又名CP1251).为了在此编码中获取字符的代码点,您需要首先将字符串编码为CP1251,然后获取结果字节的值:
# Assuming Python 3
s = "???".encode('cp1251')
for b in s:
print(b)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4004 次 |
| 最近记录: |