Python Syntax error: blank space
Python Syntax error: blank space
我是python的新手,这段代码的目的是打印文件MusicTaste.csv中的前100个常用词,并将其打印在table中。我已经解决了过去的语法错误,但以前从未见过这个错误。
请看下面的代码
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
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):
我看到的第三个问题是在下一行
中缺少 ]
[pt.add_row(kv) for kv in c.most_common()[:100]]
我是python的新手,这段代码的目的是打印文件MusicTaste.csv中的前100个常用词,并将其打印在table中。我已经解决了过去的语法错误,但以前从未见过这个错误。
请看下面的代码
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
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):
我看到的第三个问题是在下一行
中缺少]
[pt.add_row(kv) for kv in c.most_common()[:100]]