我有一个看起来像这样的字符串:
"Name1=Value1;Name2=Value2;Name3=Value3"
Python中是否有内置类/函数将采用该字符串并构造一个字典,就像我已经做过的那样:
dict = {
"Name1": "Value1",
"Name2": "Value2",
"Name3": "Value3"
}
I have looked through the modules available but can't seem to find anything that matches.
Thanks, I do know how to make the relevant code myself, but since such smallish solutions are usually mine-fields waiting to happen (ie. someone writes: Name1='Value1=2';) etc. then I usually prefer some pre-tested function.
I'll do it myself then.
s = r'Name1='Value=2';Name2=Value2;Name3=Value3;Name4="Va\"lue;\n3"'
input (note: a semicolon inside a quoted string, a quote is escaped using a backslash,\n
escape is used, both single and double quotes are used)?