mpappu mpappu - 2 years ago 91
Python Question

Is there a way to interate through all the functions of a module?

I have a list of numbers and I want to, for (for example) the first term and the second term, perform every function in my imported


import math
list = [1, 2, 3]
#do stuff that will print (for example) 2+1, 2-1, 2/1, etc.

Answer Source

Here's a simple method. You'll need to specify what happens if the function doesn't expect two arguments.

for name in dir(math):
    item = getattr(math, name)
    if callable(item):
        item(list[0], list[1])
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download