changelog shortlog graph tags branches files raw help

changeset: created

changeset 107: b25bf8fcd197
parent 106: 5e763a12e171
child 108: 04a46e901b55
author: 127.0.0.1
date: Fri, 06 Dec 2013 23:49:19 +0100
files: cached_property.py
description: created
     1.1--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2+++ b/cached_property.py	Fri Dec 06 23:49:19 2013 +0100
     1.3@@ -0,0 +1,19 @@
     1.4+class cached_property(object):
     1.5+    def __init__(self, func):
     1.6+        self.func = func
     1.7+
     1.8+    def __get__(self, instance, type):
     1.9+        if instance is None:
    1.10+            return self
    1.11+        res = instance.__dict__[self.func.__name__] = self.func(instance)
    1.12+        return res
    1.13+
    1.14+class Thing(object):
    1.15+    @cached_property
    1.16+    def four(self):
    1.17+        print "four"
    1.18+        return 4
    1.19+
    1.20+thing = Thing()
    1.21+print thing.four()
    1.22+print thing.four()
    1.23\ No newline at end of file