Issue
I have a bound classmethod refference at some point in the code. I want to get the class itself from it. How can I do it?
class A:
@classmethod
def class_method(cls):
...
...
method_reference = A.class_method
...
reference_to_A = method_reference.bound_class # how to get it?
Solution
Use __self__
:
>>> class A:
... @classmethod
... def class_method(cls):
... pass
...
>>> method_reference = A.class_method
>>> method_reference.__self__
<class '__main__.A'>
Answered By - Ofer Sadan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.