property using a classmethod

Emanuele D'Arrigo manu3d at
Thu Jul 9 06:59:45 EDT 2009


today I did something like this:

class MyClass(object):

    def myClassMethod(self):
         print "ham"

     myProperty = property(myClassMethod, None, None)

As many of you know this doesn't work and returns a TypeError: the
object passed to the property is not a callable function but a
classmethod object, which isn't callable at all. 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().

Can it be done?


More information about the Python-list mailing list