0

A python program has builtin functions and user defined functions in it. I wish to list out all the user defined functions in that program. Could any one suggest me the way to how to do it?

example:

class sample():

     def __init__(self):
         .....some code....
     def func1():
         ....some operation...
     def func2():
         ...some operation..

I need output like this:

func1

func2
3
  • Which program? Do you have any sample code? Commented May 13, 2015 at 5:52
  • any python code which has number of user defined functions. Commented May 13, 2015 at 6:19
  • 1 and 2 may be helpful. Commented Jul 12, 2020 at 2:00

2 Answers 2

0

This isn’t strictly true. The dir() function “attempts to produce the most relevant, rather than complete, information”. Source:

How do I get list of methods in a Python class?

Is it possible to list all functions in a module?

Sign up to request clarification or add additional context in comments.

Comments

0

A cheap trick in Python 3.x would be this:

sample = Sample()
[i for i in dir(sample) if not i.startswith("__")]

which returns non-magic functions that start with double underscores.

['func1', 'func2']

Comments

Your Answer

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.