Re: can't rebind magic methods

2006-03-20 Thread Alex Martelli
Michael Tobis <[EMAIL PROTECTED]> wrote: > Still a bit confused actually. Any explanation of the following? I believe the problem you're having is with WHEN a name is looked up -- which tends to be 'as late as possible, but no later'. > def getf(method,name): > def f(self, *a, **k): return m

Re: can't rebind magic methods

2006-03-20 Thread Michael Tobis
Still a bit confused actually. Any explanation of the following? mt def getf(method,name): def f(self, *a, **k): return method(self.val, *a, **k) f.func_name = name return f class myint(object): def __init__(self, val): self.val = int(val) for spec in 'str repr has

Re: can't rebind magic methods

2006-03-20 Thread Michael Tobis
Thanks! Only a minor correction: the last line should be _setdelegate(myint, int,'__%s__' % spec) The business with f.func_name struck me as unnecessary, but I was quite wrong. This was an interesting exercise for me. Thanks. Michael -- http://mail.python.org/mailman/listinfo/python-list

Re: can't rebind magic methods

2006-03-18 Thread Alex Martelli
Michael Tobis <[EMAIL PROTECTED]> wrote: > I'd appreciate an explanation of why this doesn't work and any > workarounds. Special methods are looked up (for their automatic use) on the type, not the instance. The workaround is therefore to set them on the type, too: > class myint(object): > >