Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 how can I changing a base class method
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 ?

from collections import deque
class Xdeque(deque):

    def extendleft(self,items):
        return super().extendleft(reversed(items))

d = Xdeque()
I don't believe you can. And if you can, it's would be a bad idea.
Craig "Ichabod" O'Brien -
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Thanks for this awesome answer !
I agree with you , it is a bad idea, in fact programming in general is a bad idea !

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to Call a method of class having no argument dataplumber 7 317 Oct-31-2019, 01:52 PM
Last Post: dataplumber
  Call method from another method within a class anteboy65 3 142 Sep-11-2019, 08:40 PM
Last Post: Larz60+
  How to call base class function kamal_chennai 1 306 Apr-03-2019, 01:12 PM
Last Post: ichabod801
  Why Can't I call base class function for my derived class object? AmirAB 2 384 Feb-13-2019, 03:04 PM
Last Post: snippsat
  problem with class method AmirAB 3 367 Feb-13-2019, 01:51 AM
Last Post: AmirAB
  why my method doesn't find my List in the same class? Scorpio 2 328 Jan-31-2019, 05:21 PM
Last Post: Scorpio
  Base class variables are not accessible Prabakaran141 3 523 Oct-31-2018, 07:13 AM
Last Post: buran
  The derivate class dosn't behave like the base when i pass parameter to them drudox 4 552 Aug-05-2018, 06:42 PM
Last Post: drudox
  setting base class attribute bb8 1 679 Feb-13-2018, 06:37 PM
Last Post: nilamo
  Getting attribute and changing it through method nadav 5 771 Feb-13-2018, 03:36 PM
Last Post: Windspar

Forum Jump:

Users browsing this thread: 1 Guest(s)