How to call methods in a class using the string representation of its name in Python

1 Answer

0 votes
class C_CLASS:
    def m_method(self):
        return "C_CLASS - m_method"


obj = C_CLASS()

class_method = getattr(C_CLASS, "m_method")

result = class_method(obj)

print(result)
   
   
   
   
'''
run:
   
C_CLASS - m_method
   
'''

 



answered Jun 6, 2021 by avibootz

Related questions

1 answer 230 views
1 answer 202 views
1 answer 194 views
1 answer 170 views
2 answers 166 views
166 views asked Apr 27, 2021 by avibootz
...