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.
micseydel likes this post
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
  Changing the name of a windows class? tibegato 4 198 May-17-2020, 08:25 PM
Last Post: tibegato
  calling on a method from one class into another class which is not a child NABA 5 157 Apr-29-2020, 07:49 PM
Last Post: deanhystad
  threading for method outside class anna 0 158 Nov-17-2019, 07:05 AM
Last Post: anna
  How to Call a method of class having no argument dataplumber 7 704 Oct-31-2019, 01:52 PM
Last Post: dataplumber
  Call method from another method within a class anteboy65 3 430 Sep-11-2019, 08:40 PM
Last Post: Larz60+
  How to call base class function kamal_chennai 1 462 Apr-03-2019, 01:12 PM
Last Post: ichabod801
  Why Can't I call base class function for my derived class object? AmirAB 2 539 Feb-13-2019, 03:04 PM
Last Post: snippsat
  problem with class method AmirAB 3 611 Feb-13-2019, 01:51 AM
Last Post: AmirAB
  why my method doesn't find my List in the same class? Scorpio 2 502 Jan-31-2019, 05:21 PM
Last Post: Scorpio
  Base class variables are not accessible Prabakaran141 3 711 Oct-31-2018, 07:13 AM
Last Post: buran

Forum Jump:

Users browsing this thread: 1 Guest(s)