dictionary with object's method as thier items
John Purser
jmpurser at gmail.com
Wed Aug 30 10:33:41 EDT 2006
On 30 Aug 2006 06:35:17 -0700
"noro" <amit.man at gmail.com> 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()>}
>
> and so i could access every method of instances of C, such as obj with
> sometiing like:
> (i know that this syntax wont work )
>
> obj.(d['function one'])
> obj.(d['function two'])
> etc..
>
Sure. But the syntax would be:
d['function one'] = c.func1
d['function one']()
I'm not sure what this gets you but it works.
John Purser
More information about the Python-list
mailing list