I am a Python beginner, so please forgive the noob question. I read through similar questions already but cannot find a solution, as most point to a version issue in Python, which is not the case here as I am using 3.7.6.
I am doing an exercise with urllib and encountered the aforementioned error. In order to check if my code caused it, I ran a sample code from the course website:
import urllib.request
fhand = urllib.request.urlopen('http://data.pr4e.org/romeo.txt')
for line in fhand:
print(line.decode().strip())
Please note that 'urllib.py' is the file name where I stored this code locally.
This should return the contents of the text file and print them line by line. However, I get:
Traceback (most recent call last):
File "urllib.py", line 1, in <module>
import urllib.request, urllib.parse, urllib.error
File "/Users/xxx/Documents/urllib.py", line 1, in <module>
import urllib.request, urllib.parse, urllib.error
ModuleNotFoundError: No module named 'urllib.request'; 'urllib' is not a package
We tested the code on someone else's machine and it works just fine. Any ideas what could be causing this? Thanks!