Guest User

Untitled

a guest
Jul 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. from weakref import WeakKeyDictionary as store
  2.  
  3. class WriteOnce:
  4. def __init__(self):
  5. self.__values = store()
  6. def __get__(self, obj, obj_type=None):
  7. return self.__values(obj) if obj_type is None else self
  8.  
  9. def __set__(self, obj, value):
  10. if not obj in self.__values:
  11. self.__values[obj] = value
  12. else:
  13. return AttributeError
Add Comment
Please, Sign In to add comment