Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from weakref import WeakKeyDictionary as store
- class WriteOnce:
- def __init__(self):
- self.__values = store()
- def __get__(self, obj, obj_type=None):
- return self.__values(obj) if obj_type is None else self
- def __set__(self, obj, value):
- if not obj in self.__values:
- self.__values[obj] = value
- else:
- return AttributeError
Add Comment
Please, Sign In to add comment