在python字典中删除引号 [英] Remove quotes in python dictionary

查看:1431
本文介绍了在python字典中删除引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了如下字典,

{'members': '{"mgt.as.wso2.com": 4100,"as.wso2.com": 4300}', 'subdomain': 'mgt'}

在关键成员中,值用两个单引号引起来.有没有一种方法可以删除那些单引号.我想要像这样的字典,

In the key members value is passed within two single quotes. Is there a way to remove those single quotes. I want the dictionary like following,

{'members': {"mgt.as.wso2.com": 4100,"as.wso2.com": 4300}, 'subdomain': 'mgt'}

推荐答案

使用literal_eval评估字符串值,然后将其分配回键:

Evaluate the string value with literal_eval, and then assign it back to the key:

>>> import ast
>>> d['members'] = ast.literal_eval(d['members'])
>>> d['members']['as.wso2.com']
4300

这篇关于在python字典中删除引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆