Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MySimpleNamespace:
- def __init__(self, **kwargs):
- for key, value in kwargs.items():
- self.__setattr__(str(key), value)
- some_obj = MySimpleNamespace(x=1, y=2, z=3)
- # Можно вызывать как атрибуты
- print(some_obj.x, some_obj.y, some_obj.z)
- # Можно инициализировать новые атрибуты
- some_obj.some_attribute = 'value'
- print(some_obj.some_attribute)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement