Use SimpleNamespace for better readability

from types import SimpleNamespace >>> person = SimpleNamespace(name="guido", age=15) 
>>> person namespace(name='guido', age=15)
>>> person.name 'guido'
>>> person.age 15
>>> person.email
Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'types.SimpleNamespace' object has no attribute 'email'
>>> person.email = "test@gmail.com"
>>> person namespace(name='guido', age=15, email='test@gmail.com') >>> person.email 'test@gmail.com'
>>>
>>> data = {"a": 1, "b": 2, "c":3} 
>>> data["a"] 1
>>> data_simple = SimpleNamespace(**data)
>>> data_simple namespace(a=1, b=2, c=3)
>>> data_simple.a 1
>>> data_simple.b 2
>>> data_simple.c 3
>>>

--

--

Coding, Reading,Python

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store