+1 vote
in Other by
new to python, currently reading diveintopython and trying to run the following code from the book:

def buildConnectionString(params):

   """Build a connection string from a dictionary of parameters.

      Returns string."""

      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)

Now when i hit enter, Python shell says the if statement has a syntax error?? I'm running Python 2.7.

JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The code itself is working (I just tried it). A possible reason for errors is inconsistent indentation. It seems that your lines start with different numbers of spaces (or tabs). Try changing the the blank space in the beginning of each indented line to, say, four spaces, and try running the script again.

Related questions

+1 vote
asked Feb 1, 2022 in Other by DavidAnderson
+1 vote
asked Feb 1, 2022 in Other by DavidAnderson
...