Pointing to function from class
Rainer Deyke
root at rainerdeyke.com
Tue Oct 17 14:46:17 EDT 2000
"Adam Clark" <bjrubble at shell16.ba.best.com> wrote in message
news:8sgrd7$2u3c$1 at nntp1.ba.best.com...
> Hi.
>
> I want something like this:
>
> def SomeFunc () :
> # doesn't take self and can be called from outside a class
>
> class Class :
> f = SomeFunc
>
> c = Class()
> c.f()
class Class:
def f(self, *args, **kwargs):
return apply(SomeFunc, args, kwargs)
You could even generalize this:
def adapt_function_for_class(f):
def adapted_function(self, base_function = f, *args, **kwargs):
return apply(base_function, args, kwargs)
return adapted_function
class Class:
f = adapt_function_for_class(SomeFunc)
--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor
More information about the Python-list
mailing list