Python etc / types.SimpleNamespace

types.SimpleNamespace

types.SimpleNamespace is a way to make a dict with access by attributes:

from types import SimpleNamespace
sn = SimpleNamespace(a=1, b=2)
sn.a
# 1

sn.c
# AttributeError: ...

However, values from SimpleNamespace can't be accessed by getitem anymore because "There should be only one obvious way to do it":

sn['a']
# TypeError: 'types.SimpleNamespace' object is not subscriptable