Python calls Super initialization error "super () argument 1 must be type, not Classobj" __python

Source: Internet
Author: User

PYTHON3.0 does not exist, the old version may have an error:

Class A ():
    def __init__ (self):
        print (' A ')

class B ():
    def __init__ (self):
        print (' B ')

class C ():
    def __init__ (self):
        print (' C ')

class Asub (A):
    def __init__ (self):
        print (' asub ')
        Super (asub, self). __init__ ()

class BSub (B):
    def __init__ (self):
        print (' BSub ')
        super (bsub,self ). __init__ ()

class Csub (C):
    def __init__ (self):
        print (' csub ')
        super (csub, self). __init__ ()

class E (Asub, BSub, csub):
    def __init__ (self):
        print (' E ')
        asub.__init__ (self)
        bsub.__ Init__ (self)
        csub.__init__ (self)

d = E ()

The

error occurred while calling super initialization in subclass Asub: Where A is a superclass, there is no syntax error in careful examination. Super (asub, self). Init () typeerror:super () Argument 1 must is type, not classobj for the following reasons: The method of calling the superclass directly before the python2.2 version was later changed to be called by Super, because of the resolution of the diamond in multiple inheritance Shape problems. Super in Python can only be used in new classes, not in previous classic classes, and this error occurs if the base class is a classic class. The solution is to asub as long as there is an object on the superclass OK. For example: A (object): .......

Class A (object): #!!!!!!! Based in Object!!!!!!
    def __init__ (self):
        print (' A ')

class B (object):
    def __init__ (self):
        print (' B ')

class C (object) :
    def __init__ (self):
        print (' C ')

class Asub (A):
    def __init__ (self):
        print (' asub ')
        super (Asub, self). __init__ ()

class BSub (B):
    def __init__ (self):
        print (' BSub ')
        super (bsub,self). __ INIT__ ()

class Csub (C):
    def __init__ (self):
        print (' csub ')
        super (csub, self). __init__ ()

Class E (Asub, BSub, csub):
    def __init__ (self):
        print (' E ')
        asub.__init__ (self)
        bsub.__init__ ( Self)
        csub.__init__ (self)

d = E ()

Note: When constructing a class, it is customary to inherit the base class object!!!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.