-
Notifications
You must be signed in to change notification settings - Fork 107
Quick Start
Chris Griffith edited this page Nov 2, 2024
·
2 revisions
from box import Box
my_box = Box(key="value")
print(my_box.key)
# value
That is the equivalent of the following dictionary:
my_dict = dict(key="value")
print(my_dict["key"])
# value
Keep in mind, at any time you can also access or modify the Box
in the same manor as a dictionary.
print(my_box["key"])
# value
my_box = Box({"team": {"red": {"leader": "Sarge", "members": []}}})
print(my_box.team.red.leader)
# Sarge
Any time a dict or list is added to the Box
, it is also updated to a Box
or BoxList
my_box.team.blue = {"leader": "Church", "members": []}
print(repr(my_box.team.blue))
# <Box: {'leader': 'Church', 'members': []}>
my_box.team.red.members = [
{"name": "Grif", "rank": "Minor Junior Private Negative First Class"},
{"name": "Dick Simmons", "rank": "Captain"}
]
print(my_box.team.red.members[0].name)
# Grif
Make sure to check out the limitations and how Box handles conversions to understand what edge cases may affect you!
These documents are for Box 5.0+