def underscore_memoization(func):
 name = ('_' + func.__name__)
 def wrapper(self):
  try:
   return getattr(self, name)
  except AttributeError:
   result = func(self)
   if inspect.isgenerator(result):
    result = list(result)
   setattr(self, name, result)
   return result
 return wrapper

def underscore_memoization ( func ) : name = ( '_' + func . __name__ ) def wrapper ( self ) : try : return getattr ( self , name ) except AttributeError : result = func ( self ) if inspect . isgenerator ( result ) : result = list ( result ) setattr ( self , name , result ) return result return wrapper
decorator for methods:: class a: def x: if self .