Python语法错误:空格

时间:2015-03-13 08:56:32

标签: python syntax-error

我是python的新手,这段代码用于打印文件MusicTaste.csv中前100个常用词并将其打印在表格中。我已经解决了过去的语法错误,但之前从未见过这个错误。

请参阅以下代码

import re
from collections import Counter
from prettytable import PrettyTable

words = re.findall('\w+',open('MusicTaste2.csv').read().lower())   
for label, data in ('Word', words) THE_ERROR_APPEARS_HERE_BLANK_SPACE

pt = PrettyTable(field_names=[label, 'Count'])
c = Counter(words)
[ pt.add_row(kv) for kv in c.most_common()[:100]

print pt

1 个答案:

答案 0 :(得分:2)

import re
from collections import Counter
from prettytable import PrettyTable

words = re.findall('\w+',open('MusicTaste2.csv').read().lower())   
for label, data in ('Word', words):
    pt = PrettyTable(field_names=[label, 'Count'])
    c = Counter(words)
    [pt.add_row(kv) for kv in c.most_common()[:100]]
    print (pt)

第一个问题是indent您的代码正确

下一行:缺少第二个问题

for label, data in ('Word', words):

我看到的第三个问题在以下行<{1}}中缺失

]