close
Skip to content

Be able to initialize with a flattened dict? #170

@dragonpaw

Description

@dragonpaw

I'm in a situation where I need to deal with some deeply nested structures, but I want to initialize them with dictionaries of dotted keys. So I'd ideally like to be able to do something like:

d = Box({'service.name': 'django', 'service.version': 2.2})
print(d.service.name) 
# Prints 'django'
print(d.service.keys())
# prints "dict_keys(['name', 'version'])"
print(d.to_dict())
# prints {'service': {'name': 'django', 'version': 2.2}}

Now, I can do this if I initialize the Box, then write to it as d.service.name = 'django', but it'd be nice to be able to unflatten the incoming dict somehow.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions