I'm trying to get all the user-defined methods name from a class, ex:
class MyClass:
def __init__(self, param1, param2):
pass
def one_method(self):
pass
def __repr__(self):
pass
def __str__(self):
pass
def __my_method_no_2(self, param2):
pass
def _my_method_no_3(self):
pass
so far I have come to the following approach:
import inspect
[name for name, _ in inspect.getmembers(MyClass, inspect.isroutine)
if name not in {'__init_subclass__', '__subclasshook__'} and
getattr(MyClass, name).__qualname__.startswith(MyClass.__name__)]
output:
['_MyClass__my_method_no_2',
'__init__',
'__repr__',
'__str__',
'_my_method_no_3',
'one_method']
this is the expected output, but this looks "ugly" and not even sure if is the right approach