Skip to content Skip to sidebar Skip to footer

Convert Dsn String In Python To Kwargs

I have a simple string which describes a mysql connection. The string is in this form: dsn = 'user=dbuser database=mydbase host=localhost' this string can contain many of the thin

Solution 1:

One simple method would be to use str.split:

>>> vals = "key=val key2=val2"
>>> dict(s.split("=") for s in vals.split())
{'key2': 'val2', 'key': 'val'}

Post a Comment for "Convert Dsn String In Python To Kwargs"