import nltk
from urllib import request
url = "http://www.site.uottawa.ca/~diana/csi5386/A1_2020/microblog2011.txt"
response = request.urlopen(url)
raw = response.read().decode('utf8')
tokens = nltk.word_tokenize(raw)
tokens
在上面的代码中,输出以列表的形式出现在“令牌”中。如何将此列表复制到文本文件中?
您需要执行以下操作:
with open('filename.txt', 'w') as f:
for i in tokens:
f.write(i)