Comments (3)
Currently no, but I am not opposed to that as a feature.
from box.
Found a 'cheap' way to do this:
In [1]: from box import Box
In [2]: box_data = Box(box_dots=True, default_box=True)
In [3]: box_data.a.b.c = 1
In [4]: box_data.a.b.c
Out[4]: 1
In [5]: v = 1234
In [6]: exec('box_data.c.a.b = v', locals())
In [7]: box_data.c.a.b
Out[7]: 1234
The exec mechanism can be used if you have a key as a string too:
In [8]: key = 'z.y.x'
In [9]: exec(f'box_data.{key} = v', locals())
In [10]: box_data.z.y.x
Out[10]: 1234
Optimally a better way wouldn't require something like an exec call.
from box.
With Box 7 going to have it so you can combine default_box and box_dots as you described and have it work with dots in strings as well. So:
a = Box(box_dots=True, default_box=True)
a['b.c'] = 3
# Box({'b': {'c': 3}})
from box.
Related Issues (20)
- I can create a method in a box that overwrite a key HOT 2
- cannot froze a subclass HOT 4
- Feature request: add additional values from file HOT 3
- Feature request: only one function for loading files HOT 3
- Support for tracking the box "namespace" HOT 6
- Feature Request: default to an empty dict for missing keys HOT 3
- Version mismatch between setup.py and tag HOT 3
- Two small typos in Wiki / Types of Boxes HOT 3
- Breaking convention with __or__/ __ror__ dunder methods HOT 3
- Using help (`?`) with `default_box=True` unintentionally adds a key HOT 3
- Keys method with (dotted=True) gives multiplication of the same key HOT 1
- `__add__` and `__or__` operators for frozen boxes HOT 3
- Add Cython builds to MacOS using `universal2` HOT 4
- Switch to poetry-core HOT 2
- Missing python-box 7.0.0 arm64 wheels HOT 1
- BoxKeyError when constructing a Box with box_dots = True in v7.0.0 HOT 2
- Appending a list to a list causes recursion HOT 4
- IDE Auto Completion for keys
- merge_update() not merging nested dictionaries or lists HOT 1
- path as string HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from box.