You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					13 lines
				
				343 B
			
		
		
			
		
	
	
					13 lines
				
				343 B
			| 
											6 years ago
										 | class lazy_property():
 | ||
|  |   """Defines a property whose value will be computed only once and as needed.
 | ||
|  | 
 | ||
|  |      This can only be used on instance methods.
 | ||
|  |   """
 | ||
|  |   def __init__(self, func):
 | ||
|  |     self._func = func
 | ||
|  | 
 | ||
|  |   def __get__(self, obj_self, cls):
 | ||
|  |     value = self._func(obj_self)
 | ||
|  |     setattr(obj_self, self._func.__name__, value)
 | ||
|  |     return value
 |