Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (7.3k points)

The following use of super() raises a TypeError: why?

>>> from HTMLParser import HTMLParser

>>> class TextParser(HTMLParser):

... def __init__(self):

... super(TextParser, self).__init__() 

... self.all_data = [] 


>>> TextParser()


TypeError: must be type, not classobj

What am I missing? How can I use super(), here?

Using HTMLParser.__init__(self) instead of super(TextParser, self).__init__() would work, but I would like to understand the TypeError.

1 Answer

0 votes
by (106k points)

To remove the above Type error that you are getting while using the super(). The super() can only be used in the new-style classes, that means the root or the parent  class needs to inherit from the 'object' class

An example, that shows how the root class need to be:

class SomeClass(object):

def __init__(self): ....

The solution for this is to call the parent's init method directly like as follows:

from HTMLParser import HTMLParser

class TextParser(HTMLParser):

def __init__(self):


self.all_data = []

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.5k answers


108k users

Browse Categories