2

I want to get every methods of an object. I know about the function dir but it returns all(method, attr, meta_data).

I tried this:

[x for x in dir(obj) if "_" not in x]

but it does not work correctly.

How can I do it?

Filippo Vitale
  • 7,597
  • 3
  • 58
  • 64
Tany
  • 393
  • 1
  • 4
  • 16
  • possible duplicate of [Finding what methods an object has](http://stackoverflow.com/questions/34439/finding-what-methods-an-object-has) – Rene Korss Jul 15 '15 at 07:10

2 Answers2

4

you need see inspect. For example

inspect.getmembers(object, inspect.ismethod)

it returns only method.

Anna
  • 53
  • 5
4

You can filter dir result

[method for method in dir(obj) if callable(getattr(obj, method))]
itzMEonTV
  • 19,851
  • 4
  • 39
  • 49