How do I say "Is this a function"?

John Henry john106henry at hotmail.com
Sun Apr 27 00:01:51 EDT 2008


On Apr 26, 6:08 pm, "Martin v. Löwis" <mar... at v.loewis.de> wrote:
> > def f1():
> >    print "In f1"
>
> > def f3():
> >    print "In f3"
>
> > def others():
> >    print "In others"
>
> > for i in xrange(1,3):
> >    fct = "f%d()"%(i+1)
> >    try:
> >       exec fct
> >    except:
> >       others()
>
> I'd write that as
>
> for i in xrange(1,3):
>     globals().get("f%d" % (i+1), others)()
>
> Regards,
> Martin

Perfect.  Works great.  No EXEC.

You guys are great.



More information about the Python-list mailing list