12

I new to python. I use Python 3.3 in Eclipse Kepler.

This is my code snippet:

f = Fibonacci(0,1)
for r in f.series():
    if r > 100: break
    print(r, end=' ')

At the line print(r, end = ''), eclipse reports a syntax error - Syntax error while detecting tuple. However, the program runs perfectly.

Why does this happen and how do I fix the error?

4
  • 4
    Eclipse must be calibrated for Python 2.x, in which print(r, end=' ') would be illegal syntax.
    – user2555451
    Mar 18, 2014 at 19:26
  • @iCodez - I don't understand. I am using py 3.3. So, how does this apply to me ? Mar 18, 2014 at 19:29
  • 1
    Just because you're using py 3.3 doesn't mean Eclipse knows that.
    – kenm
    Mar 18, 2014 at 19:33
  • 1
    I mean, the system that Eclipse is using to check your syntax might be following Python 2.x's syntax rules. The code you posted is fine for Python 3.x but it would raise a SyntaxError in Python 2.x. In other words, your IDE is causing the problem; the code is fine. You need to find a way to tell Eclipse to follow Python 3.x's syntax rules. I do not know how to do this because I do not use Eclipse, so that is why I am commenting instead of posting an answer.
    – user2555451
    Mar 18, 2014 at 19:33

5 Answers 5

23

You need to specify the correct Grammar Version in Eclipse. See here: print function in Python3

Is Grammar Version 3.3 in your setup? Steps - Project > Properties > Python Interpreter/Grammar. You might have to restart Eclipse to see the changes.

1
  • 4
    I got my mistake. I went to windows > preferences and set the python INTERPRETER there. It should be Project > Properties > Python Interpreter/Grammar. I had to restart Eclipse to see the changes. Mar 18, 2014 at 20:59
3

I know this is an old post, but for those of you with similar issues in 2018 and later, CodeMix for Eclipse is a plugin you can install to boost your python development with almost none configuration needed. You get Content Assist, Validation, shortcut commands for stuff from refactoring to formatting, etc. More informaiton here

1

In python 2.x print is a built-in keyword, not a function as in python 3.x and is used like this :

>>> print "hello", "world"
hello world

Therefore, Python assumes that (r, end= '') is a tuple containing two values, that you are trying to print.

You can probably configure eclipse to use python 3.x syntax. Check this if you are using PyDev.

0

Change the run path in eclipse to python 3.x rather than its current setting which is probably set to python 2.x

1
  • 2
    Can you expand this answer---e.g., why you think Eclipse would be set to use Python 2 versus Python 3, etc. One-sentence answers tend to be frowned on here, even if they contain correct information, and are likely to get converted into comments. Mar 18, 2014 at 20:07
0

I think it's possible you're actually using Python 2. Do this and report your results:

import sys
print(sys.version)

EDIT:

Actually, what you're reporting appears to be an open bug on pydev for Eclipse:

http://sourceforge.net/p/pydev/bugs/913/

1
  • 1
    Is this really an answer to the question? Should it not be a comment? Mar 18, 2014 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.