def getattr_(obj, name, default_thunk):
 try:
  return getattr(obj, name)
 except AttributeError:
  default = default_thunk()
  setattr(obj, name, default)
  return default

def getattr_ ( obj , name , default_thunk ) : try : return getattr ( obj , name ) except AttributeError : default = default_thunk ( ) setattr ( obj , name , default ) return default
similar to .