[Tutor] question about classes and atributes
Alan Gauld
alan.gauld at btinternet.com
Sat Nov 4 01:21:43 CET 2006
"Kent Johnson" <kent37 at tds.net> wrote
> Alan Gauld wrote:
>> I'm not sure about adding methods at run time, I've never
> Sure it works:
>
> In [1]: class foo(object): pass
> ...:
> In [4]: def show(self): print "Hi, I'm a foo"
>
> In [5]: foo.show=show
>
> In [6]: f.show()
> Hi, I'm a foo
Cool!
I'm constantly amazed at the power and simplicity of Python.
> More advanced explanation:
Yes, it makes sense when its explained.
But I'd never have intuitively thought of that!
Thanks for the info Kent.
Alan G.
More information about the Tutor
mailing list