Syntax error waiting for newline

I am using python 2.7.3 PyDev in Eclipse. From the source code of the porter streamer

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()

      

I am getting the error

Found "output" at line 336, column 23. Expecting one of:
 ... "(" ... "[" ... ";" ... "," ... "." ... "+ "..." - "..." ... "/" ... "//" ...
"& ; <" ... "→" ... "%" ... "^ "..." | "..." & "..." = "..."> "..." <"..." == "..." <= "..."> = "..."! = "..." + = "..." - = "..." = "..." / = "..." // = "..."% = "..." & = "..." | = "..." ^ = "..." <<= "..." → = "..." ** = "..." or "..." and "..." not "...
"is" ... "in" ... "if" ... "; ...", "...

+3


source to share


3 answers


Check which version of Python grammar you are using (can't remember if it's global or per project). It looks like your grammar is set for Py3k, which is print

now a function instead of an operator.



Edit: I see no reason for this code not to run normally unless PyDev has wrapped your hands around it - if you can't run it directly from python.exe invoked from the command line, this is some kind of hidden bad syntax that I missed.

+5


source


Try print

as a function ...

print(output)

      



Also, check your Eclipse settings to see which version of python you are using ...

+2


source


So the problem was that PyDev has a built-in interpreter that it uses in the editor, but it uses an external interpreter when running the code. Although only python 2.7.3 was installed on my computer and it was configured automatically with eclipse pydev, the built-in interpreter was installed in 3.0. Also, the built-in interpreter option is not available from the options menu in PyDev, but it is hidden. When one right click on the project title in the file explorer and select properties, then there is another interpreter option. In addition, all editor windows must be closed and reopened to use the updated settings.

+2


source







All Articles