'urllib package: modules not included
I've imported the urllib package but it doesn't seem to come with its modules out of the box like I was used to expect.
>>> import urllib
>>> dir(urllib.request)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'urllib' has no attribute 'request'
>>> dir(urllib)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']
>>> from urllib import request
>>> dir(urllib)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'error', 'parse', 'request', 'response']
The docs describe urllib as "a package that collects several modules for working with URLs". Does it mean anything particularly?
I mean, usually packages when imported fully (import package) deliver "the whole package".
So, is urllib a particular type of package in that sense, i.e. is there a way to know when to expect this kind of behavior?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
