【发布时间】:2018-01-31 14:04:47
【问题描述】:
用python
ord('a')
给予
97
但是
ord('é')
报错
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: ord() expected a character, but string of length 2 found
如何获取除 ASCII (é = 233) 以外的其他字母的小数点,例如 https://en.wikipedia.org/wiki/List_of_Unicode_characters#Latin-1_Supplement?
【问题讨论】:
-
你用的是什么python版本?我在 python 2 和 3 中尝试了同样的方法,都运行良好。
-
我在 Python 2.7.9 中遇到了同样的问题,但在 Python 3.4.2 中运行良好
-
为了重现,您需要一个以 UTF-8 编码但缺少
encoding: utf-8注释的文件。我认为这只会影响 Python 2。
标签: python character-encoding decimal iso-8859-1