Calling functions in a loop
Nick Perkins
nperkins7 at home.com
Sat Jul 14 14:35:18 EDT 2001
for Fn in Fn1, Fn2:
Fn()
(don't use eval!)
"NANDYALA D Gangadhar" <n_d_gangadhar at yahoo.com> wrote in message
news:7b9380ca.0107140919.b80cd8 at posting.google.com...
> 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