Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
删除python字典中的引号_Python_Python 2.7_Dictionary - Fatal编程技术网

删除python字典中的引号

删除python字典中的引号,python,python-2.7,dictionary,Python,Python 2.7,Dictionary,我有一本字典,如下所示 {'members': '{"mgt.as.wso2.com": 4100,"as.wso2.com": 4300}', 'subdomain': 'mgt'} {'members': {"mgt.as.wso2.com": 4100,"as.wso2.com": 4300}, 'subdomain': 'mgt'} 在键成员中,值在两个单引号内传递。有没有办法删除这些单引号。我想要下面这本字典 {'members': '{"mgt.as.wso2.com": 410

我有一本字典,如下所示

{'members': '{"mgt.as.wso2.com": 4100,"as.wso2.com": 4300}', 'subdomain': 'mgt'}
{'members': {"mgt.as.wso2.com": 4100,"as.wso2.com": 4300}, 'subdomain': 'mgt'}
在键成员中,值在两个单引号内传递。有没有办法删除这些单引号。我想要下面这本字典

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

使用
literal\u eval
计算字符串值,然后将其分配回键:

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

那些词典是一样的,不是吗?你想用第二个例子的格式打印词典吗?因为字典本身是一样的。或者你想解析其中一个词典吗?不。第一个词典包含“成员”:“{”mgt.as.wso2.com“:4100,“as.wso2.com”:4300}”我需要的是如下没有单引号的成员:{”mgt.as.wso2.com“:4100,“as.wso2.com”:4300}你想让这个值本身成为词典吗?@AnubianNoob我想解析词典。为了做到这一点,我需要第二种格式的字典。我会选择
ast.literal\u eval()
而不是
eval()
@TigerhawkT3是的,你是对的,我不知道它(修复)