3

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
8,1633 gold badges65 silver badges66 bronze badges
asked Jul 15, 2015 at 6:58
1

2 Answers 2

5

you need see inspect. For example

inspect.getmembers(object, inspect.ismethod)

it returns only method.

answered Jul 15, 2015 at 6:59
Sign up to request clarification or add additional context in comments.

Comments

4

You can filter dir result

[method for method in dir(obj) if callable(getattr(obj, method))]
answered Jul 15, 2015 at 7:01

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.