Created
May 19, 2010 18:59
-
-
Save macek/406698 to your computer and use it in GitHub Desktop.
My First Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Build a connection string from a dictionary of paramters | |
| # Returns string | |
| def build_connection_string params | |
| params.map{ |k,v| "%s=%s" % [k,v] }.join ";" | |
| end | |
| my_params = { | |
| server: "mpilgrim", | |
| database: "master", | |
| uid: "sa", | |
| pwd: "secret" | |
| } | |
| puts build_connection_string(my_params) | |
| #=> pwd=secret;database=master;uid=sa;server=mpilgrim |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()]) | |
| myParams = { | |
| "server": "mpilgrim", | |
| "database": "master", | |
| "uid": "sa", | |
| "pwd": "secret" | |
| } | |
| print buildConnectionString(myParams) | |
| #=> pwd=secret;database=master;uid=sa;server=mpilgrim | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment