Recursively access dict via attributes as well as index access?
I'd like to be able to do something like this:from dotDict import dotdictifylife = {'bigBang': {'stars': {'planets': []} } }dotdictify(life)# This would be the regular...
View ArticleAnswer by Curt Hagenlocher for Recursively access dict via attributes as well...
Here's one way to create that kind of experience:class DotDictify(dict): MARKER = object() def __init__(self, value=None): if value is None: pass elif isinstance(value, dict): for key in value:...
View ArticleAnswer by kadee for Recursively access dict via attributes as well as index...
Below another implementation of a nested attribute dictionary (inspired by the answer of Curt Hagenlocher, stripped down to the essential):class AttrDict(dict):""" Nested Attribute Dictionary A class...
View ArticleAnswer by Oliver for Recursively access dict via attributes as well as index...
Here is another solution: from typing import Dict, Anyclass PropertyTree: passdef dict_to_prop_tree(yaml_config: Dict[str, Any]) -> PropertyTree: tree = PropertyTree() for key, value in...
View ArticleAnswer by 蒋兴邦 for Recursively access dict via attributes as well as index...
#!/usr/bin/env python3# _*_ coding: utf-8 _*_# Author: Xingbang Jiang# E-mail: 1278561590@qq.com# HomePage: http://www.xingbangsharing.techclass Dotsdict(dict): def __init__(self, args, **kwargs):...
View ArticleAnswer by ramazan polat for Recursively access dict via attributes as well as...
There is a package doing exactly what you want and also something more and it is called Prodict.from prodict import Prodictlife_dict = {'bigBang': {'stars': {'planets': []} } }life =...
View Article