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
  threading for method outside class anna 0 85 Nov-17-2019, 07:05 AM
Last Post: anna
  How to Call a method of class having no argument dataplumber 7 457 Oct-31-2019, 01:52 PM
Last Post: dataplumber
  Call method from another method within a class anteboy65 3 221 Sep-11-2019, 08:40 PM
Last Post: Larz60+
  How to call base class function kamal_chennai 1 361 Apr-03-2019, 01:12 PM
Last Post: ichabod801
  Why Can't I call base class function for my derived class object? AmirAB 2 439 Feb-13-2019, 03:04 PM
Last Post: snippsat
  problem with class method AmirAB 3 433 Feb-13-2019, 01:51 AM
Last Post: AmirAB
  why my method doesn't find my List in the same class? Scorpio 2 371 Jan-31-2019, 05:21 PM
Last Post: Scorpio
  Base class variables are not accessible Prabakaran141 3 582 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 593 Aug-05-2018, 06:42 PM
Last Post: drudox
  setting base class attribute bb8 1 741 Feb-13-2018, 06:37 PM
Last Post: nilamo

Forum Jump:

Users browsing this thread: 1 Guest(s)