| Home > Dive Into Python > Getting To Know Python > Summary | << >> |
| diveintopython.org | |
| Python for experienced programmers | |
The odbchelper.py program and its output should now make perfect sense.
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)Example 1.36. Output of odbchelper.py
server=mpilgrim;uid=sa;database=master;pwd=secret
Before diving into the next chapter, make sure you're comfortable doing all of these things:
| « Joining lists and splitting strings | The Power Of Introspection » |