[英]Convert string to dictionary where keys are not strings
I am parsing an html file an I end up with something that almost looks like a python dictionary... except for the keys not being strings. 我解析HTML文件的我最终的东西, 几乎看起来像一条巨蟒字典...除了键不是字符串。 Because of this I cannot use
ast.literal_eval()
or json.loads()
. 因此我不能使用
ast.literal_eval()
或json.loads()
。
The string looks like this: 字符串看起来像这样:
x = '{name:'Berlin, Germany', daypart:'night', href:'/en/de/berlin/10178/weather-forecast/178087', icon:'http://vortex.accuweather.com/adc2010/images/icons-numbered/33-m.png', bg:'cl', temp:'22', realfeel:'22', text:'Clear'}'
I want to convert this into a python dictionary where the keys are also strings. 我想将其转换为python字典,其中键也是字符串。 I think this need some good ol' regex but I don't know how to do it.
我认为这需要一些好的'正则表达式,但我不知道该怎么做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.