Py2 Classical Class, inheritance problem

class A ():

def __init__(self):
    print("A")

class B (A):

def __init__(self):
    super(B, self).__init__()

b = B ()
* * an error occurred when executing under py2
super (B, self). _ init__ ()
TypeError: must be type, not classobj**

there is no problem if parent class A uses the new class
class A (object):

def __init__(self):
    print("A")

Why!?

Mar.10,2021

python.org/2/library/functions.html?highlight=super-sharpsuper" rel=" nofollow noreferrer "> super description

super (type [, object-or-type])

Note: super () only works for new-style classes.


I don't know the nuances between Python2 and Python3, but I think there's something wrong with your inheritance.

super(B, self).__init__()

Why do you inherit class B under custom class B? Let B be both a son and a father, go against the laws of nature and affirm Error. As said on the first floor: "super () only works for new-style classes."

maybe I misunderstood it. If there are any mistakes, please don't be stingy and guide me to correct them.

Menu