[Tutor] Declaring methods in modules.
Chris Fuller
cfuller084 at thinkingplanet.net
Sun Apr 11 18:57:50 CEST 2010
Sorry, should have included a concrete example. Although, as the others have
said, I'm not sure how it helps with what you (seem) to want to do.
0 % cat bar.py
def the_answer(self):
return 42
0 % cat foo.py
import bar
class A:
pass
setattr(A, '__call__', bar.the_answer)
a=A()
print a()
class B(object):
pass
setattr(B, '__call__', bar.the_answer)
b=B()
print b()
0 % python foo.py
42
42
Cheers
More information about the Tutor
mailing list