Re: Adding new methods to new-style classes dynamically

2005-05-05 Thread Jack Diederich
On Thu, May 05, 2005 at 01:35:09AM -0700, Max Derkachev wrote: > Good day to all. > > Some time ago I'd been playing with a framework which uses dynamic > class creation havily. Say, I could do: > > #well, try this with the new-style class > class A(object): > pass > > # the new-style __dic

Re: Adding new methods to new-style classes dynamically

2005-05-05 Thread Max Derkachev
John Machin wrote: > >>> A.foo > 123 Oh, I've been a little dumb to forget about it :) Thanks. Max. -- http://mail.python.org/mailman/listinfo/python-list

Re: Adding new methods to new-style classes dynamically

2005-05-05 Thread John Machin
Max Derkachev wrote: [snip] > #well, try this with the new-style class > class A(object): > pass > > # the new-style __dict__ is a dictproxy object > A.__dict__[meth_name] = lambda self: type(self) > >>Traceback (most recent call last): > >> File "", line 1, in ? > >>TypeError: object does not

Re: Adding new methods to new-style classes dynamically

2005-05-05 Thread Michele Simionato
Do you mean setattr? setattr(A, meth_name, lambda self: type(self)) Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list