Asterisk in Python

Hey, is there anyway to fix Komodo showing syntaxerror when using asterisk inside the function?

See my code below,

def mysum(L):
    first, *args = L
    return first if not args else first + mysum(args)

and the error message

  File "D:\Python\Book\", line 114
    first, *args = L
SyntaxError: invalid syntax

This doesn’t appear in any other IDE. Can someone help me? Is there something I have to activate (error ignore) etc?

Thanks and sorry if it’s a wrong thread

You seem to be writing Python 3 code, but have probably selected Python as the language. Make sure you select “Python 3” in the language dropdown menu in your statusbar. You can change the default association for Python files under Preferences > File Associations.

Hey Nathan, tried on both versions, 2.7 and 3.4+. Same error :frowning:


You don’t understand properly what Nathan said. Change the language here:
(the bottom of Komodo).
If you want to associate your *.py files with Python 3 by default, go to Preferences - File Associations, find the *.py item and change the language to Python 3. Be sure to check Show Advanced checkbox to see File Associations item in the preferences list.

Also check your Python interpreter preference for Python 3 and ensure it’s not using Python 2 by mistake.

Preferences > Languages > Python 3

By default Komodo uses the Python interpreter for syntax checking. If it’s using Python 2 for Python 3 syntax it will throw the error you are seeing.

I think this should be prevented by Komodo, like if you try to set the Python 2.7 interpreter for Python 3, Komodo should throw a warning/error that it’s not something you should do and reset the interpreter to the default one (Find on Path option). What do you think about that?

Thanks all, it wasn’t the case of the preferences. But that my run macro was set to run the code in 2.7 … my bad :slight_smile: fixed now

Glad you sorted it out!