Init a table of functions

Richard Blackwood richardblackwood at
Sun Oct 10 05:06:15 CEST 2004

Robert Kern wrote:

> 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.
> Move the table outside of the class definition
> class foo(object):
>     def f1():
>         print 'f1'
>     f1 = staticmethod(f1)
> foo.K = {'f1': foo.f1,
>         }
> foo.K['f1']()
Right Right Right. 

Notice how he added the "object" as an arg to class foo.

More information about the Python-list mailing list