questions about dir and import in python -
i have questions python's dir function
>>>import urllib >>>dir(urllib) ['__builtins__', '__cached__', '__doc__', '__file__','__loader__','__name__','__package__', '__path__', '__spec__']
and when this
>>>import urllib.request >>>dir(urllib) ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__','__package__', '__path__', '__spec__', 'error', 'parse', 'request', 'response']
why comes 3 more attributes? why request attribute doesn't in dir(urllib) @ first?
i' appriciate help!
urllib
package, whereas in urllib.request
, request
module inside urllib
package.
when import package, not automatically import modules inside package, unless module imported __init__.py
package.
but __init__.py
of urllib
empty (its empty in python 3.4) , , hence when importing urllib
not import module urllib.request
.
Comments
Post a Comment