Skip to content

Instantly share code, notes, and snippets.

@macek
Created May 19, 2010 18:59
Show Gist options
  • Select an option

  • Save macek/406698 to your computer and use it in GitHub Desktop.

Select an option

Save macek/406698 to your computer and use it in GitHub Desktop.
My First Python
# 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
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