2

I am learning python and have a problem passing a parameter. According to the documentation, the HTMLParser class is defines as follows:

class html.parser.HTMLParser(strict=False, *, convert_charrefs=False)

In my derived class I like to pass True in the convert_charrefs parameter. How can I do that? Here is my code so far

from html.parser import HTMLParser

class MyParser( HTMLParser ):
    def __init(self)__:
        super(MyParser, self).__init__( ??? )

So, what should i write instead of ??? to pass a True value in convert_charrfs?

Update: The obvious solution is to call __init__(convert_charrefs=True) I did try that, but it did not work for me because I was using python 3.3.4 instead of 3.4

1
  • 3
    def __init__(self) not def __init(self)__ Commented Apr 11, 2014 at 13:11

2 Answers 2

3

That would be

super(MyParser, self).__init__(convert_charrefs=True)
Sign up to request clarification or add additional context in comments.

2 Comments

I have tried that but I get the error message: TypeError: __init__() got an unexpected keyword argument 'convert_charrefs'
Are you sure you are using Python version 3.4 or higher? The convert_charrefs keyword was added in 3.4.
2
from html.parser import HTMLParser

class MyParser(HTMLParser):
    def __init__(self):
        super(MyParser, self).__init__(convert_charrefs=True)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.