Hi, can you help me figure out what I need to add to remove this error in Python
ID: 3903301 • Letter: H
Question
Hi, can you help me figure out what I need to add to remove this error in Python? It is unable to open and read my sourcefile with url links.
40 41 42 43 # for each line, pull contents from web using urllib if len(sys.argv) -3 45 46 47 48 49 50 51 52 53 54 55 Cannot find reference 'urlopen' in 'imported module urllib imported module urllib' more... (9F1) 56 57 58 59 60 61 62 63 64 65 print("Error: Invalid arguments") print("Usage:aggregator.py filename topic") file open(sys.argv [1], "r") out sys.argv [2]"summary.txt" file1 open(out, "w") for line in file: try: response urllib.urlopen(line) ton for Tine1 content: List - line1.split(">") list -list[1].split("") # check contents for match to topic if sys.argv [2] in list[0]: if count0 # if match, write contents to file filel.write(linel +" ") file1.write( countcount +1 file1.write(linel) file1.write(" In") 67 68 69 70 71 72if namemai 73 except file1.write("Error opening URL:" + line + " ") main()Explanation / Answer
The "imports" statements are not visible in the screenshot.
I assume, you are using Python 3.
Add the following import statement and comment the earlier import urllib statement
from urllib.request import urlopen
and in line #53, you can modfiy it to response = urlopen(line)
Let me know if it doesnt work and also share the complete code
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.