Python Forum
super() and order of running method in class inheritance
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
super() and order of running method in class inheritance
#4
(Feb-01-2024, 07:54 AM)Gribouillis Wrote:
(Feb-01-2024, 07:21 AM)akbarza Wrote: explain to me why Python acts as this.
This is explained in the documentation of super
Documentation Wrote:The search starts from the class right after the type.

For example, if __mro__ of object_or_type is D -> B -> C -> A -> object and the value of type is B, then super() searches C -> A -> object.
In your case, the __mro__ of g is grandchild -> child1 -> child2 -> parent -> object So in child1, super() finds child2 before parent.

hi, thanks for the reply
I think I read the segment of document about super() at least five
Reply


Messages In This Thread
RE: super() and order of running method in class inheritance - by akbarza - Feb-02-2024, 07:56 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problems with super() Hoespilaar 3 540 Jun-11-2024, 02:15 AM
Last Post: kanetracy
  class definition and problem with a method HerrAyas 2 441 Apr-01-2024, 03:34 PM
Last Post: HerrAyas
  super() in class akbarza 1 721 Dec-19-2023, 12:55 PM
Last Post: menator01
  the order of running code in a decorator function akbarza 2 686 Nov-10-2023, 08:09 AM
Last Post: akbarza
  "Name is not defined" when running a class lil_e 6 4,690 Jan-12-2023, 11:57 PM
Last Post: lil_e
  Using one child class method in another child class garynewport 5 1,861 Jan-11-2023, 06:07 PM
Last Post: garynewport
  Child class inheritance issue eakanathan 3 1,510 Apr-21-2022, 12:03 PM
Last Post: deanhystad
  [Solved] Novice question to OOP: can a method of class A access attributes of class B BigMan 1 1,437 Mar-14-2022, 11:21 PM
Last Post: deanhystad
  class, attribute and method Frankduc 9 2,775 Feb-27-2022, 09:07 PM
Last Post: deanhystad
  Subclass initialized property used in parent class method. Is it bad coding practice? saavedra29 5 2,099 Feb-07-2022, 07:29 PM
Last Post: saavedra29

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020