dictionary with object's method as thier items
Georg Brandl
g.brandl-nospam at gmx.net
Wed Aug 30 10:50:18 EDT 2006
noro wrote:
> Is it possible to do the following:
>
> for a certain class:
>
> ----------------------------
> class C:
>
> def func1(self):
> pass
> def func2(self):
> pass
> def func4(self):
> pass
>
> obj=C()
> ----------------------------
>
> by some way create a dictionary that look somthing like that:
>
> d= {'function one': <reference to C.func1()>, \
> 'function two': <reference to C.func2()>, \
> 'function three': <reference to C.func3()>}
Perhaps this:
>>> class C:
... def function(self, arg):
... print arg
...
>>> obj = C()
>>> d = C.__dict__
>>> d['function'](obj, 42)
42
>>>
Georg
More information about the Python-list
mailing list