Pour obtenir une liste de(s) méthode(s) d'un objet donnée on peut utiliser la ligne de code suivante: methodList = [method for method in dir(objet) if callable(getattr(objet, method))] en remplaçant objet par le nom de votre instance . Un exemple simple:
class MyClass():
def Meth_01(self):
return 'Hello World !'
def Meth_02(self):
return 'Hello Universe !'
def Meth_03(self):
return 'Hello Earth !'
ins = MyClass()
methodList = [method for method in dir(ins) if callable(getattr(ins, method))]
print methodList
Le script ci-dessus donne alors le résultat suivant:
['Meth_01', 'Meth_02', 'Meth_03']
Recherches associées
Liens | Site |
---|---|
Finding what methods an object has | stackoverflow |
Dive Into Python | Dive Into Python Doc |
Inspect python class attributes | stackoverflow |
Python dir(dict) vs dir(dict.class) | stackoverflow |
Printing all instances of a class | stackoverflow |
Built-in Functions | python doc |
Is there a function in Python to print all the current properties and values of an object? | stackoverflow |
How do I get list of methods in a Python class? | stackoverflow |