Init a table of functions

Andrew Dalke adalke at mindspring.com
Sun Oct 10 05:56:13 CEST 2004


Richard Blackwood wrote:
> Yo Andrew.  That doesn't work.  Check my previous post w/ errors.

What do you mean?

Ahh, I see I solved the first problem (can't find 'foo')
without solving what the OP wanted.  Try this reordering.

class foo:
      def f1():
           print "f1"

      def f2():
           print "f2"

      K={"f1" : f1,
         "f2" : f2,
         }
      f1 = staticmethod(f1)
      f2 = staticmethod(f2)

def main():
      foo.K["f1"]()
      foo.K["f2"]()

if __name__ == "__main__":
      main()

The 'staticmethod' is a descriptor and only works in
the context of a class.

Functions get turned into methods only in the context
of a class.

So to use a function as a function, get it before it
turns into a method or staticmethod.

				Andrew
				dalke at dalkescientific.com



More information about the Python-list mailing list