Calling functions in a loop

NANDYALA D Gangadhar n_d_gangadhar at yahoo.com
Sat Jul 14 13:19:35 EDT 2001


Hello,

I am new to Python (I already like it very much) and I have a newbee
question: How do I call a set of functions from inside a loop? I tried 
the following, and it understanbly fails with:

TypeError: object is not callable: 'Fn1'

-- Code --
#!/usr/bin/env python
 
__all__ = ["Fn1", "Fn2"]
 
def Fn1():
        print "I am Fn1"
 
def Fn2():
        print "I am Fn2"
 
if __name__ == "__main__":
        for Fn in __all__:
                Fn()    
-- /Code --

Would someone show the correct way of getting the functionality I need?

Thanks,
Gangadhar



More information about the Python-list mailing list