0

ok can someone explain why this code dosen't work

import urllib.request, urllib.parse, urllib.error

fhand = urllib.request.urlopen('http://data.pr4e.org/romeo.txt')

counts = dict()
for line in fhand:
    words = line.decode().split()
    for word in words:
    counts[word] = counts.get(word, 0) + 1
print(counts)

i get this traceback

Traceback (most recent call last):
  File "C:\Users\boris\OneDrive\Desktop\python\urllib.py", line 1, in <module>
    import urllib.request, urllib.parse, urllib.error
  File "C:\Users\boris\OneDrive\Desktop\python\urllib.py", line 1, in <module>
    import urllib.request, urllib.parse, urllib.error
ModuleNotFoundError: No module named 'urllib.request'; 'urllib' is not a package
  • What is your file name? Its work for me. – Samsul Islam Jun 16 '20 at 20:56
  • As @SamsulIslam alluded to, try naming your python file something other than `urlllib.py`. Python can be a bit particular about filenames which conflict with package names, in cases like this. [This answer may be helpful.](https://stackoverflow.com/a/4092446/3857192) – Ben Delaney Jun 17 '20 at 06:14

0 Answers0