I need to be able to convert any string in the format
"var1=var a;var2=var b"
to a dictionary and I managed to do that as follows.
a = "a=b;b=2"
def str_to_conf_dict(input_str):
return dict(u.split('=') for u in input_str.split(';'))
b = str_to_conf_dict(a)
result= {'a': 'b', 'b': '2'}
But the values in the dictionary have quotes regardless whether var a
, var b
is a number or an alphabet.
I know that the values are always going to be a mix of characters and numbers (int/float/negatives). How would I have the quotes if the variable is a character and remove the quotes if it is a number?
It is crucial to have the quotes only on characters because I will pass the values to functions which work specifically if it meets the criteria, there is no way to modify that end.