On Friday 17 October 2003 10:52 pm, Paul Moore wrote: ... > >> selector = Top.__get__(10) ... > Urk. I just checked, and this works. But I haven't the foggiest idea > why! Could someone please explain? If you do, I promise never to > reveal who told me :-) Functions are descriptors, and func.__get__(obj) returns a bound method with im_self set to obj -- that's how functions become bound methods, in today's Python, when accessed with attribute syntax obj.func on an instance obj of a class which has func in its dict. But the mechanism is NOT meant for general currying... you could say the latter just works as a weird-ish side effect, and not in too general a way: consider for example: >>> def p(s): print s ... >>> p.__get__('one case').__get__('another')() another >>> the second __get__ "replaces" the im_self [[it works on _p_ again, the im_func of the bound method given by the first, NOT on "the bound method itself", as that isn't a descriptor]]... now if we had a marketing dept it could sell this as a feature, "rebindable curried functions", perhaps, but in fact it's an "accidental side effect"...;-) Alex
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4