Python Forum

Full Version: Syntax error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Fairly new to Python, so I need help with the following:
I am getting a syntax error for parser = MyHTMLParser() and I can't figure out why?

#
# Example file for parsing and processing HTML
#
from html.parser import HTMLParser

class MyHTMLparser(HTMLParser):
def handle_comment(self, data):
print("Encountered comment: ", data)
pos = self.getpos()
print ("\tAt Line: ", pos[0], " position ", pos[1]



# instantiate the parser and feed it some HTML
parser = MyHTMLParser()
f = open("samplehtml.html")
if f.mode == 'r'
contents = f.read()
parser.feed(contents)




























def main():

if __name__ == "__main__":
main();
The issue is that the line above where you get syntax error
print ("\tAt Line: ", pos[0], " position ", pos[1]
is missing closing parentheses.

For future posts, please use Python code tags for code, and post full error traceback message in error tags.