Emanuele D'Arrigo wrote:
class MyClass(object):
@classmethod
def myClassMethod(self):
print "ham"
myProperty = property(myClassMethod, None, None)
... doesn't work and returns a TypeError: .... So, how do I do this?
Ultimately all I want is a non-callable class-level attribute
MyClass.myProperty that gives the result of MyClass.myClassMethod().
properties affect instances, and classes are instances of types.
What you want is a new metaclass:
class MyType(type):
@property
def demo(class_):
return class_.a + 3
class MyClass(object):
__metaclass__ = MyType
a = 5
print MyClass.a, MyClass.demo
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list