Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

property

  • Loading branch information...
commit c190d73b36e8a567932b2eb0a43f3fa3c9122e13 1 parent 6114e3a
@albertz authored
Showing with 22 additions and 0 deletions.
  1. +22 −0 py-descr-property.py
View
22 py-descr-property.py
@@ -28,3 +28,25 @@ class B:
print "b.x:", b.x
print b.__class__.x
+
+# ---
+
+class initBy(property):
+ def __init__(self, initFunc):
+ property.__init__(self, fget = self.fget)
+ self.initFunc = initFunc
+ def fget(self, inst):
+ if hasattr(self, "value"): return self.value
+ self.value = self.initFunc()
+ return self.value
+
+def initFuncTest():
+ print "initFuncTest"
+ return "x"
+
+class C:
+ x = initBy(initFuncTest)
+
+c = C()
+print "c.x:", c.x
+print "c.x:", c.x
Please sign in to comment.
Something went wrong with that request. Please try again.