Hello. If you look at "A better Python object for JSON take 2" , It was written about how to access dictionary values (you can access it as in the source below). A similar one has been made and seems to have been a hot topic for a long time:
- Dot access to fields instead of []
>>> from easydict import EasyDict as edict
>>> x = edict({'cos':1})
>>> x
{'cos': 1}
>>> x['cos']
1
>>> x.cos
1
>>> x['sin']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'sin'
>>> x.sin
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'EasyDict' object has no attribute 'sin'
Recommended Posts