Bruno Desthuilliers a écrit :
(snip)
You could write your own custom descriptor. Or just use an additional
level of indirection, ie:
myProperty = property(lambda self: self.myClassMethod())
Sorry, looks like I didn't read carefully enough. The above code won't
work if you intend to looku
Lie Ryan a écrit :
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
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.
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 attrib
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 overcomplex
Emanuele D'Arrigo wrote:
> Greetings,
>
> today I did something like this:
>
> class MyClass(object):
>
> @classmethod
> def myClassMethod(self):
> print "ham"
>
> myProperty = property(myClassMethod, None, None)
>
> As many of you know this doesn't work and returns a Typ
Emanuele D'Arrigo a écrit :
Greetings,
today I did something like this:
class MyClass(object):
@classmethod
def myClassMethod(self):
Usually, the first argument of classmethods is named 'cls'
print "ham"
myProperty = property(myClassMethod, None, None)
As many of
Greetings,
today I did something like this:
class MyClass(object):
@classmethod
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