Gabriela Sokołowska
Gabriela Sokołowska

Reputation: 29

Why am I having "Invalid syntax in Python?"

In the following code sample, the last line (print buildConnectionString(myParams)) is throwing the following error:

Invalid syntax

def buildConnectionString(params):

return ";".join(["%s=%s" % (k, v) for k, v in params.items()])

if __name__ == "__main__":
    myParams = {"server":"mpilgrim", \
                "database":"master", \
                "uid":"sa", \
                "pwd":"secret"
               }
    print buildConnectionString(myParams) 

Upvotes: 1

Views: 49

Answers (1)

Randy
Randy

Reputation: 14849

Assuming that you're on Python 3, print is a function and needs to be wrapped in parentheses:

print(buildConnectionString(myParams))

Upvotes: 7

Related Questions