我在Eclipse中使用python 2.7.3 PyDev。从porter stemmer source code语法错误,期待换行
if __name__ == '__main__':
p = PorterStemmer()
if len(sys.argv) > 1:
for f in sys.argv[1:]:
infile = open(f, 'r')
while 1:
output = ''
word = ''
line = infile.readline()
if line == '':
break
for c in line:
if c.isalpha():
word += c.lower()
else:
if word:
output += p.stem(word, 0,len(word)-1)
word = ''
output += c.lower()
print output # ---- ERROR
infile.close()
我得到的错误
遭遇 “输出” 的行336,列23期待之一:
...... “(” ... “[” ...“,”...“,”...“。” ...“+”...“ - ”...“”...“/”...“//” ...
“< <”...“>>”...“%”...“^”...“|”...“&”... “=”... “>”...“<“...”==“...”< =“...”> =“... ”!=“...”+ =“...” - =“...” =“...”/ =“...”// =“ ...”%=“...”& =“...”| =“...”^ =“...” < < =“... ”>> =“...”** =“...”或“...”和“...”不是“...
”是“... “...”如果“...”;“...”,“...”
您的代码是有效的Python 2语法,也许Eclipse使用Python 3语法。尝试从命令行运行脚本。 – martineau