Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Python function call error - newbie question

Status
Not open for further replies.

peterv12

Technical User
Dec 31, 2008
108
US
I'm trying to learn Python online, using DiveIntoPython.org. The first example program I have tried is this:

Code:
def buildConnectionString(params):
	"""Build a connection string from a dictionary
	
	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)

I'm running this in an OS X Terminal and I'm getting the following error message:

Code:
/Users/peterv/bin/test1.py: [b][COLOR=red]line 1: syntax error near unexpected token `('[/color][/b]
/Users/peterv/bin/test1.py: [b][COLOR=red]line 1: `def buildConnectionString(params):'
[/color][/b]

Can anyone explain what the problem is? I did a cut & paste from the pdf, so it should work, according to the book. I don't see any syntax error.
 
Never Mind! I just realized that I need the #!/user/bin/python line at the top.
Sorry....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top