Skip to main content
 首页 » 编程设计

python之如何在 Python 中获取 ASCII 西里尔字符代码

2025年05月04日25jillzhang

ord() 返回 unicode 代码,我需要 ascii。

>>> s = "Йог" #cyrillic 
>>> for char in s: 
...     print(ord(char)) 
...  
1049 #unicode 
1086 #unicode 
1075 #unicode 

我需要 ASCII。如何获得? (下)

请您参考如下方法:

你不能; ASCII 中没有西里尔字符.您显示的图表是众多 "extended ASCII" 中的一个。字符集;具体来说,它似乎是 Windows-1251 (又名 CP1251)。为了获得此编码中字符的代码点,您需要首先将字符串编码为 CP1251,然后获取结果字节的值:

# Assuming Python 3 
s = "Йог".encode('cp1251') 
for b in s: 
    print(b)