Tany
Tany

Reputation: 423

Can i get all methods of a python object?

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?

Upvotes: 3

Views: 6095

Answers (2)

itzMEonTV
itzMEonTV

Reputation: 20369

You can filter dir result

[method for method in dir(obj) if callable(getattr(obj, method))]

Upvotes: 4

Anna
Anna

Reputation: 63

you need see inspect. For example

inspect.getmembers(object, inspect.ismethod)

it returns only method.

Upvotes: 5

Related Questions