In article <[EMAIL PROTECTED]>, "Michele Simionato" <[EMAIL PROTECTED]> wrote:
> Ron Garret wrote: > > One of the things I find annoying about Python is that when you make a > > change to a method definition that change is not reflected in existing > > instances of a class (because you're really defining a new class when > > you reload a class definition, not actually redefining it). So I came > > up with this programming style: > > > > def defmethod(cls): > > return lambda (func): type.__setattr__(cls, func.func_name, func) > > Why not just ``return lambda func: setattr(cls, func.func_name, func)`` > ? Because I'm an idiot. (i.e. yes, that is obviously the right way to do it.) > The only thing I don't like is that all your > functions/methods will end up begin 'None'. > > I'd rather to be able to use > the help, so I would write > > def defmethod(cls): > def decorator(func): > setattr(cls, func.func_name, func) > return func > return decorator > > @defmethod(C) > def m1(self, x):pass > > help(m1) > > > BTW, for people with a Lisp background I recommend using IPython with > emacs and the > ipython.el mode. It is pretty good, even if not comparable to Slime. > > Michele Simionato Good tips. Thanks! rg -- http://mail.python.org/mailman/listinfo/python-list