prof-rossetti / intro-to-python

An Introduction to Programming in Python
Other
97 stars 245 forks source link

Simple Namespace #98

Closed s2t2 closed 2 years ago

s2t2 commented 3 years ago

Provides object-like dot notation for dicts.

from types import SimpleNamespace

d = {'key1': 'value1', 'key2': 'value2'}

n = SimpleNamespace(**d)
print(n.key1)

References: