property using a classmethod

Lie Ryan lie.1296 at gmail.com
Thu Jul 9 13:35:19 EDT 2009


Bruno Desthuilliers wrote:
> Lie Ryan a écrit :
>> Emanuele D'Arrigo wrote:
> (snip)
>>> Ultimately all I want is a non-callable class-level attribute
>>> MyClass.myProperty that gives the result of MyClass.myClassMethod().
>>
>> This works like what you seem to want (it's ugly):
> 
> Ugly, indeed. And an extreme case of arbitrary overcomplexification too :-/
> 
> (snip rube goldberg code)
> 

Can't think of anything simpler than that without meddling with
descriptor. I'm not even sure descriptor can help here as it seems
descriptor needs an instance? (I've just skimmed it, so I may be wrong)

The ugliness of the code hints to two possible reasons:
- there should be a better way
- if there isn't an easier way, then something is wrong the class' design



More information about the Python-list mailing list