I have a class with a property method:
class SomeClass(object):
@property
def some_method(self):
return True
I want to make a call to some_method and store it in as an expression.
For example:
some_expr = SomeClass().some_method
Should not store the value True in some_expr; rather should store the expression SomeClass().some_method so that it is callable.
How can I implement this?
Note, you essentially want to use the .__get__ callable on the property instance. However, this will require an instance as the first argument, so you could just partially apply some instance:
In [6]: class SomeClass(object):
...:
...: @property
...: def some_method(self):
...:
...: return True
...:
In [7]: from functools import partial
Then something like:
In [9]: some_exp = partial(SomeClass.some_method.__get__, SomeClass())
In [10]: some_exp()
Out[10]: True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With