Init a table of functions
Richard Blackwood
richardblackwood at cloudthunder.com
Sat Oct 9 21:55:12 EDT 2004
Paulo da Silva wrote:
> How do I program something like the folowing program?
> PYTHON claims it doesn't know about 'foo' when initializing K!
> The only way I got this to work was doing the init of K in
> the __init__ func. But this runs everytime for each object!
> When using the name of the function without 'foo', I don't
> know how to call it!
>
> Thanks for any help.
>
> #! /bin/env python
> # -*- coding: iso-8859-15 -*-
>
> class foo:
> def f1():
> print "f1"
> f1=staticmethod(f1)
>
> def f2():
> print "f2"
> f2=staticmethod(f2)
>
> K={"f1" : foo.f1, \
> "f1" : foo.f2 \
> }
>
>
> def main():
> foo.K["f1"]()
> foo.K["f2"]()
>
> if __name__ == "__main__":
> main()
self.f1 and self.f2 should work within any class. Try that.
More information about the Python-list
mailing list