简体   繁体   English

使用python dpath库删除嵌套对象

[英]Delete nested objects using python dpath library

I want to perform a delete operation using python's dpath and delete the nested objects using the separator parameter.我想使用python的dpath执行删除操作并使用separator参数删除嵌套对象。 But I cannot delete the nested objects.但我无法删除嵌套对象。 Below is my code下面是我的代码

import dpath.util
    
    dictionary = {
            "a": {
                "b": {
                    "c": 0
                     }
                }
            }
dpath.util.delete(dictionary, "a.b.c", separator=".")

After the delete operation, the dictionary is {'a': {'b': {}}} whereas the the desired dictionary is {'a':{}}删除操作后,字典为{'a': {'b': {}}}而所需的字典为{'a':{}}

This works:这有效:

import dpath.util

dictionary = {
            "a": {
                "b": {
                    "c": 0
                     }
                }
            }

dpath.util.delete(dictionary, "a.*", separator=".")

After this operation, dictionary is now {'a': {}} .在此操作之后, dictionary现在是{'a': {}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM