如何将列表中存储的字符串转换为utf8?

时间:2019-06-09 13:40:39

标签: python-3.x

我已经将文本标记化为存储在列表中的文本文件,并将标记化的文本存储在变量中,当我打印该变量时,它将显示错误的结果。

import glob

files = glob.glob("D:\Pakistan Constitution\*.txt")

documents = []

for file in files:

    with open(file) as f:

        documents.append(f.read())

stoplist = set('for a of the and to in'.split())

texts = [[word for word in document.lower().split() if word not in stoplist] for document in documents]

print(texts)

我希望标记词出现,但是结果却是这样

  

['ÿþp\ x00a \ x00r \ x00t \ x00','\ x00v \ x00','\ x00','\ x00r \ x00e \ x00l \ x00a \ x00t \ x00i \ x00o \ x00n \ x00n \ x00s \ x00' ,'\ x00b \ x00e \ x00t \ x00w \ x00e \ x00e \ x00n \ x00',

所以任何人都可以在这方面帮助我

0 个答案:

没有答案