0

Edit: PYTHON 2.6 ... so not technically a duplicate question .....

I'm trying to figure out how to use Python on Eclipe using this tutorial but I'm stuck on part 4.Debugging. using this code:

def add(a,b):
    return a+b

def addFixedValue(a):
        y = 5
        return y +a

print add(1,2)
print addFixedValue(1)

I added a breakpoint, but still get an error:

    print add(1,2)
            ^
SyntaxError: invalid syntax

enter image description here

Raksha
  • 1,572
  • 2
  • 28
  • 53
  • 99% chance you forgot a closing parenthesis on the previous line. – TigerhawkT3 Dec 13 '16 at 00:08
  • 2
    Python 3 expects brackets around the arguments to `print`: `print(add(1,2))`. – Ken Y-N Dec 13 '16 at 00:09
  • provide your full code –  Dec 13 '16 at 00:09
  • 1
    Are you sure you've tried it in Python 2? – TigerhawkT3 Dec 13 '16 at 00:10
  • @TigerhawkT3, yes, I first tried it in 2.6 like the tutorial suggested. – Raksha Dec 13 '16 at 00:12
  • @KenY-N, thanks, that made the error go away, but now I got another error "'Perspective Switch Job' has encountered a problem." – Raksha Dec 13 '16 at 00:12
  • If it went away when you added parentheses, you were in fact not running it in Python 2. – TigerhawkT3 Dec 13 '16 at 00:15
  • @TigerhawkT3, I'm running Python 3 now :) But the first time I tried it was in Python 2.6 and it didn't work. Lemme try switching it back again. – Raksha Dec 13 '16 at 00:17
  • @KenY-N, any thoughts?.... – Raksha Dec 13 '16 at 00:52
  • @TigerhawkT3, doesn't work in 2.6 .... – Raksha Dec 13 '16 at 00:52
  • Make a script with nothing but `__import__('sys').stdout.write(__import__('sys').version)` and run that. – TigerhawkT3 Dec 13 '16 at 00:54
  • @TigerhawkT3, says "3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:15:05) [MSC v.1600 32 bit (Intel)]" .... so it's actually 3.4? What the hell... How do I change it then? – Raksha Dec 13 '16 at 01:42
  • It looks like you're telling Eclipse to inspect your source code as Python 2 code, but "Interpreter" is set to default. What options are available for that? Do you actually have Python 2 installed? – TigerhawkT3 Dec 13 '16 at 02:29
  • I'm not sure. Probably not %\ welp, I guess I'll just stick with 3 and hopefully everything works. Thanks for help. – Raksha Dec 13 '16 at 02:33
  • What do you mean, "probably not"? You've either installed it or you haven't. If you have, it should show up under the "Interpreter" drop-down menu, which I would guess is what determines what installed version of Python is actually used to run the script. – TigerhawkT3 Dec 13 '16 at 02:53
  • @TigerhawkT3, I mean I've installed Eclipse several years ago when i needed it for a class, but haven't used it since, so i don't remember what was installed on it or how it even works anymore. Under "interpreter" it just says "Default" and "Python 3" which I just installed. So I'm not sure what the "default" is, which is what i used in this case. – Raksha Dec 13 '16 at 05:21
  • 1
    If it only lists Python 3, I'd say that you'll only be able to run scripts under Python 3, which, as the only option, makes sense as the default. If you want to run scripts with Python 2, you will need to install Python 2. – TigerhawkT3 Dec 13 '16 at 05:23

1 Answers1

2

Your code is correct according to python 2.

As you are getting syntax error, you must be using python 3. In that case, you need to add parenthesis around print statement

print (add(1,2))
  • Added a screenshot. It's definitely Python 2. I guess I could just use Python 3, but I still wonder why it didn't work. – Raksha Dec 13 '16 at 00:30