Efficient Wrappers for Instance Methods
__peter__ at web.de
Wed Feb 3 16:19:35 EST 2016
Sven R. Kunze wrote:
> On 03.02.2016 22:06, Bernardo Sulzbach wrote:
>> I may say something wrong, but this is what I see going on:
>> When you get "replace = heapreplace" you are creating a data attribute
>> called replace (you will access it by self.replace or
>> variable.replace) that is an alias for heapreplace.
>> When you call x.replace(2) you are calling heapreplace(2), NOT
>> heapreplace(self, 2).
> It is exactly as you've described it.
> Question now is how can I circumvent/shortcut that? There are several
> proposals out there in the Web but none of them works. :-/
You could try putting
self.heappush = functools.partial(heapq.heappush, self)
into the initializer.
More information about the Python-list