Python 如何将标记化文本列表打印到文件中

Python 如何将标记化文本列表打印到文件中,python,Python,在上面的代码中,我的输出是列表形式的变量标记 输出样本: from urllib import request from redditscore.tokenizer import CrazyTokenizer tokenizer = CrazyTokenizer() url = "http://www.site.uottawa.ca/~diana/csi5386/A1_2020/microblog2011.txt" for line in request.url

在上面的代码中,我的输出是列表形式的变量标记

输出样本:

 from urllib import request
    from redditscore.tokenizer import CrazyTokenizer
    tokenizer = CrazyTokenizer()
    url = "http://www.site.uottawa.ca/~diana/csi5386/A1_2020/microblog2011.txt"
    for line in request.urlopen(url):
        tokens = tokenizer.tokenize(line.decode('utf-8'))
        #print(tokens)
    with open('your_file.txt', 'a') as f:
        print(tokens)
        for item in tokens:
            f.write("%s\n" % item)
现在我正试图将这个输出打印到一个文本文件中


我该怎么做?请帮助..

只需使用
''。使用每个令牌项加入

如下所示(我假设我已经拥有数组中的数据):


你的文件里有什么?有什么错误吗?您的代码面临什么问题?以及?你的问题到底是什么???注意,在你当前的代码中,你只能从源代码的最后一行获得标记。是的,我只能得到最后一行输出。但我需要将所有输出打印到文件中。我该怎么做@像我这样的人,我的产出远不止这些。我刚贴了一个样品。我正在标记超过40000行。那么如何将所有这些打印到一个文件中@拉德万·阿布·奥德
['\ufeffsave', 'bbc', 'world', 'service', 'from', 'savage', 'cuts'] 
['a', 'lot', 'of', 'people', 'always', 'make', 'fun', 'about', 'the', 'end', 'of', 'the', 'world', 'but', 'the', 'question', 'is', '"are', 'u', 'ready', 'for', 'it'] 
['rethink', 'group', 'positive', 'in', 'outlook', 'technology', 'staffing', 'specialist', 'the', 'rethink', 'group', 'expects', 'revenues', 'to', 'be']
tokens = [
    ['\ufeffsave', 'bbc', 'world', 'service', 'from', 'savage', 'cuts'],
    ['a', 'lot', 'of', 'people', 'always', 'make', 'fun', 'about', 'the', 'end', 
     'of', 'the', 'world', 'but', 'the', 'question', 'is', '"are', 'u', 'ready', 
     'for', 'it'],
    ['rethink', 'group', 'positive', 'in', 'outlook', 'technology', 'staffing', 
     'specialist', 'the', 'rethink', 'group', 'expects', 'revenues', 'to', 'be']
]
with open('your_file.txt', 'a') as f:
    print(tokens)
    for item in tokens:
        f.write("%s\n" % ' '.join(item))
with open('your_file.txt', 'a') as f:
    for line in request.urlopen(url):
        tokens = tokenizer.tokenize(line.decode('utf-8'))
        #print(tokens)
        for item in tokens:
            f.write("%s\n" % item)