Dive Into Python

Python for experienced programmers

1.15. Summary

The odbchelper.py program and its output should now make perfect sense.

Example 1.38. odbchelper.py


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)

Example 1.39. 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

| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |

The Power Of Introspection >>

Copyright © 2000, 2001, 2002 Mark Pilgrim

AltStyle によって変換されたページ (->オリジナル) /