Can someone help me debug my python code in the main function. There are red und
ID: 3903279 • Letter: C
Question
Can someone help me debug my python code in the main function. There are red underlines that need to be fixed.
aggregator.py x 21 def main): 23 24 25 26 27 28 29 30 31 32 # read command line, filename, topic filename sys.argvl-1] # read file, line by line with open (filename) as f: content f.readlines() for line in lines: # for each line, pull contents from web using urllib if len(sys.argv)-3: print("Error: Invalid arguments") print("Usage:aggregator.py filename topic") file open (sys.argv [1] ,''r") out sys.argv [2] +"sources.txt" file1 open (out,"w") for line in file: 34 35 36 37 38 39 40 41 42 43 try: response = urllib.urlopen (line) content response.read() count0 for linel in content: ust-line1. split (">") List = list [1] . split("Explanation / Answer
Hi, As you had asked for, here are the fixes for the Syntax errors (marked in red).
Line# 29 - lines (this list is undeclared and unassigned). The earlier statement content = f.readlines() must have been lines = f.readlines()
Line #54 - except: - this statement needs to be moved to left. It should be at the same level as the "try:" (line #38)
Line #55: Semi colon is not required here.
Please note : there are other (non-syntactial) errors that are not marked in red. Line #37 - variable line is not being used, line 43 and 44, the variable "list" is not being used.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.