语法错误,期待换行

sia*_*mii 3 python pydev python-2.7

我在Eclipse中使用python 2.7.3 PyDev.来自porter stemmer的源代码

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()
Run Code Online (Sandbox Code Playgroud)

我收到了错误

在第336行第23栏遇到"输出".期待以下之一:
......"("......"["......";"......","......"."......" +"..." - "......" "..."/"..."//"...
"<<"...">>"......"%"......" ^"..."|"""&"..."="......">"......"<"..."=="......"<="......" > ="..."!="..."+ ="..." - ="..."
="..."/ ="..."// ="..."% ="..."&="......"| ="......"^ ="..."<< ="...">> ="......"**="...... "或"......"和"......"不是"......
"在"......"中是"......"如果"......";"......","......

m.b*_*ley 5

检查您正在使用的Python语法版本(如果是全局或每个项目设置,则无法调用).看起来你的语法是为Py3k设置的,其中print现在是一个函数而不是一个语句.

编辑:我认为没有理由让代码无法正常运行,前提是PyDev没有全力以赴 - 如果你不能直接从命令行调用的python.exe运行它,实际上可能会有一些偷偷摸摸的我错过了错误的语法.