Nov-10-2019, 07:27 PM
Is there some ways to change methods from a base class ?
here an example, I want to change the behavior of extendleft
form deque.
yes I can create a subclass, but I need to rewrite all code that
use deque to Xdeque instead.
Is there a way to change that method instead in the base class ?
here an example, I want to change the behavior of extendleft
form deque.
yes I can create a subclass, but I need to rewrite all code that
use deque to Xdeque instead.
Is there a way to change that method instead in the base class ?
from collections import deque class Xdeque(deque): def extendleft(self,items): return super().extendleft(reversed(items)) d = Xdeque() d.extend((4,5,6,7)) d.extendleft((1,2,3)) print(d)