Quantcast
Channel: Recursively access dict via attributes as well as index access? - Stack Overflow
Browsing index pages (6 articles)

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 Article


Answer 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 Article


Answer 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 Article

Answer 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 Article

Answer 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 Article


Answer 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
Browsing index pages (6 articles)


Latest Images