2014-05-14 44 views
2

爲什麼我的Python 3.4安裝中不能使用urlliburllib上缺少方法

我可以進口,但我不能用任何方法:

Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 bit (AMD64)] on win32 
Type "copyright", "credits" or "license()" for more information. 
>>> import urllib 
>>> dir(urllib) 
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__'] 

編輯:

我無法看到子模塊之一:

>>> dir(urllib.request) 
Traceback (most recent call last): 
    File "<pyshell#2>", line 1, in <module> 
    dir(urllib.request) 
AttributeError: 'module' object has no attribute 'request' 
>>> 
+1

你必須先導入'urllib.request',然後調用'就可以了dir'。 – dano

回答

3

dir是誤導您。在Python 3.X的urllib幾個子模塊:https://docs.python.org/3.4/library/urllib.html

>>> import urllib 
>>> dir(urllib) 
['__builtins__', '__cached__', '__doc__', '__file__', '__name__', '__package__', '__path__'] 
>>> import urllib.request 
>>> dir(urllib.request) 
['AbstractBasicAuthHandler', 'AbstractDigestAuthHandler', 'AbstractHTTPHandler', 'BaseHandler', 'CacheFTPHandler', 'ContentTooShortError', 'FTPHandler', 'FancyURLopener', 'FileHandler', 'HTTPBasicAuthHandler', 'HTTPCookieProcessor', 'HTTPDefaultErrorHandler', 'HTTPDigestAuthHandler', 'HTTPError', 'HTTPErrorProcessor', 'HTTPHandler', 'HTTPPasswordMgr', 'HTTPPasswordMgrWithDefaultRealm', 'HTTPRedirectHandler', 'HTTPSHandler', 'MAXFTPCACHE', 'OpenerDirector', 'ProxyBasicAuthHandler', 'ProxyDigestAuthHandler', 'ProxyHandler', 'Request', 'URLError', 'URLopener', 'UnknownHandler', '__builtins__', '__cached__', '__doc__', '__file__', '__name__', '__package__', '__version__', '_cut_port_re', '_ftperrors', '_have_ssl', '_localhost', '_noheaders', '_opener', '_parse_proxy', '_proxy_bypass_macosx_sysconf', '_safe_gethostbyname', '_thishost', '_urlopener', 'addclosehook', 'addinfourl', 'base64', 'bisect', 'build_opener', 'collections', 'email', 'ftpcache', 'ftperrors', 'ftpwrapper', 'getproxies', 'getproxies_environment', 'hashlib', 'http', 'install_opener', 'io', 'localhost', 'noheaders', 'os', 'parse_http_list', 'parse_keqv_list', 'pathname2url', 'posixpath', 'proxy_bypass', 'proxy_bypass_environment', 'quote', 'random', 'randombytes', 're', 'request_host', 'socket', 'splitattr', 'splithost', 'splitpasswd', 'splitport', 'splitquery', 'splittag', 'splittype', 'splituser', 'splitvalue', 'ssl', 'sys', 'thishost', 'time', 'to_bytes', 'unquote', 'unwrap', 'url2pathname', 'urlcleanup', 'urljoin', 'urlopen', 'urlparse', 'urlretrieve', 'urlsplit', 'urlunparse'] 
+0

感謝您的回答,但我無法看到子模塊。 – stenci

+0

@stenci是否導入它們實際失敗? – dano

+0

導入不會顯示錯誤消息。帖子上的輸出完全從空閒狀態複製。 – stenci