Python 如何存储非英语文本?

Python 如何存储非英语文本?,python,encoding,character-encoding,python-2.x,Python,Encoding,Character Encoding,Python 2.x,我有一个文本文件。它由许多非英语字符组成。我想将此文件存储为数字序列,如ascii 如何表示非英语字符 >>> str(ord('x')) '120' >>> str(ord('ç')) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: ord() expected a character, but string of

我有一个文本文件。它由许多非英语字符组成。我想将此文件存储为数字序列,如ascii

如何表示非英语字符

>>> str(ord('x'))
'120'
>>> str(ord('ç'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: ord() expected a character, but string of length 2 found
>>> 
str(ord('x')) '120' >>>str(ord(‘ç’)) 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 TypeError:ord()应为字符,但找到长度为2的字符串 >>>
您必须首先使用正确的编码方案对其进行
解码,然后您将获得该字符的序数值,因为
ord
返回一个字符串的整数值:


为什么要将其存储为数字序列?为机器学习技术创建数据集。
>>> s = 'ç'
>>> s
'\xc3\xa7'
>>> print s
ç
>>> len(s)
2
>>> s.decode('utf-8')
u'\xe7'
>>> len(s.decode('utf-8'))
1
>>> ord(s.decode('utf-8'))
231