Stephan Kristyn
Stephan Kristyn

Reputation: 15752

Get Rid of SyntaxError: invalid syntax in Python

def success(self, input1: str = "", input2: str = "", input3: str = "") -> None:
E                               ^
E   SyntaxError: invalid syntax

No idea what is happening here..

Code:

 def success(self, input1: str = "", input2: str = "", input3: str = "") -> None:
        input1 = str(input1)
        input2 = str(input2)
        input3 = str(input3)
        print(Color.BOLD + Color.GREEN + " " + Color.CHECKMARK + " " + input1 + Color.END + " " + input2 + " " + input3)

Upvotes: 3

Views: 1051

Answers (2)

John Lyon
John Lyon

Reputation: 11440

The function you posted is valid Python 3.7. Type hints were added to Python in version 3.5.0, the code you posted should work in any version from 3.5.0 onwards:

Python 3.7.0 (default, Aug 22 2018, 20:50:05) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> def success(self, input1: str = "", input2: str = "", input3: str = "") -> None:
...         input1 = str(input1)
...         input2 = str(input2)
...         input3 = str(input3)
...         print(Color.BOLD + Color.GREEN + " " + Color.CHECKMARK + " " + input1 + 
Color.END + " " + input2 + " " + input3)
... 
>>> success
<function success at 0x7fb70e4c61e0>

I suspect you are using an older python version that does not support these language features.

Upvotes: 3

Prune
Prune

Reputation: 77910

Since you're on Python 2.7, you need to back up to that syntax. Type hints are Python 3; remove them.

def success(self, input1="", input2="", input3=""):

Upvotes: 6

Related Questions