[Tutor] How to compile "odbchelper.py" app used in "diveintopython" book ?

Hitesh N Brahmbhatt b_hitesh@hotmail.com
Sun, 11 Feb 2001 11:32:46 -0800


When I compile this file, it gives me an SyntaxError on
for statement. In the Python documentation I have the
for loop is always used as follows :

for i in list:

while the "odbchelper.py" uses it as

[(%s=%s) % (k, params[k]) for k in params.keys()]

So, I tried to put the ":" at the end of the for statement
but it doesn't help.

Can you tell me what is wrong ? I am pasting the whole prgram
and the output below:

def buildConnectionString(params):
    """Build a connection string from a dictionary of parameters.

    Returns string."""
    return ";".join(["%s=%s" % (k, params[k]) for k in params.keys()])

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

output of "python odbchelper.py" :

  File "odbchelper.py", line 5
    return ";".join(["%s=%s" % (k, params[k]) for k in params.keys()])
SyntaxError: invalid syntax