A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/cdgriffith/Box/wiki/Quick-Start below:

Quick Start · cdgriffith/Box Wiki · GitHub

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': []}>
Access Boxes Inside Lists
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!


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4