super() Raises `TypeError: must be type, not classobj`
If you try to use Python’s super method, and receive TypeError: must be type, not classobj
, your parent class is an old style class (and does not in some way inherit from object). The below code is an illustration of the issue:
class class_A: def __init__( self ): print 'Class A' class class_B( class_A ): def __init__( self ): print 'Class B' super( class_B, self ).__init__() class_B() # Running the above will raise `TypeError: must be type, not classobj`
The Fixed Code:
class class_A( object ): #< Note the inheritance of `object`. def __init__( self ): print 'Class A' class class_B( class_A ): def __init__( self ): print 'Class B' super( class_B, self ).__init__() class_B() # Running the above will no longer raise `TypeError: must be type, not classobj`9
thanks Las.. it helped me a lot.
Thanks! Helped me too :)
Thanks alot