I would like to create a class ("MyClass") that can accept a dictionary as an argument:
>>> d = {'key1', 'value1', 'key2', 'value2'}
>>> obj = MyClass(d)
The dictionary keys can be accessed as attributes:
>>> obj.key1
'value1'
The dictionary keys can be set like attributes:
>>> obj.key2 = 'a new value'
>>> obj.key2
'a new value'
An exception is raised if a key is accessed that wasn't in the dictionary:
>>> obj.key3
AttributeError: 'MyClass' object has no attribute 'key3'
There are also a few valid attributes that aren't in the dictionary but are settable. MyClass would know about them internally.
>>> obj.valid_attribute1 = 'this is a valid attribute'
Other attributes (that aren't valid) aren't allowed:
>>> obj.invalid_attribute = 5
AttributeError: 'MyClass' object has no attribute 'invalid_attribute'
I think this is similar to how a Pandas Series object works:
>>> import pandas as pd
>>> import numpy as np
>>> s = pd.Series(np.array([1,2]),index=['a','b'])
>>> s.a = 3
>>> s
a 3
b 2
dtype: int32