【发布时间】:2020-05-18 18:48:50
【问题描述】:
这是我的文本文件 (sample.txt)。
É
Â
Ê
Î
Ç
Ô
È
Û
Ï
Ë
À
Ù
Ü
现在,当我调用 python 脚本来读取这些字符的 ord() 值时,我总是收到195。这是为什么呢?
file = open("C:\sample.txt", "r")
for line in file:
print ord(line[0])
file.close()
195 的 ord() 值是这个字符:Ã,我在上述任何一行中都不存在。我期待在以下序列的输出中:
201, 194, 202, 206, 199, 212, 200, 219, 207, 203, 192, 217, 220.
【问题讨论】:
-
仅供参考,但不再支持python 2,您应该切换到python 3。
-
@Xilpex 可能有帮助——对于 Python 3.7,
ord('É')是 201
标签: python utf-8 python-2.x non-ascii-characters ord