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:
{{{ lang=python lines=1
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:
{{{ lang=python lines=1
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`
}}}
Leave a Reply to Ram Mourya Cancel reply