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
Anthon
  • 69,918
  • 32
  • 186
  • 246

2 Answers2

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?

Community
  • 1
  • 1
Ranvijay Sachan
  • 2,407
  • 3
  • 30
  • 49
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']
remykarem
  • 2,251
  • 22
  • 28