在新的Python版本中,Python3.x雖然在主要的核心語言和模塊等方面沒有打的改變,可是Python3.x與2.x仍是有很大區別的。並且Python3.x與2.x並不兼容。
好比說HTTPServer這個模塊在3.x中它存放在http.server中,可是在2.x中並無這個model。在2.x中它被放在BaseHTTPServer中。
所以,咱們能夠同過dir()函數查看一個內置模塊的屬性列表和文檔字符串。
E:\html5>python Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> import BaseHTTPServer >>> dir(BaseHTTPServer) ['BaseHTTPRequestHandler', 'DEFAULT_ERROR_CONTENT_TYPE', 'DEFAULT_ERROR_MESSAGE' , 'HTTPServer', 'SocketServer', '__all__', '__builtins__', '__doc__', '__file__' , '__name__', '__package__', '__version__', '_quote_html', 'catch_warnings', 'fi lterwarnings', 'mimetools', 'socket', 'sys', 'test', 'time'] >>> dir(CGIHTTPServer) ['BaseHTTPServer', 'CGIHTTPRequestHandler', 'SimpleHTTPServer', '__all__', '__bu iltins__', '__doc__', '__file__', '__name__', '__package__', '__version__', '_ur l_collapse_path', 'copy', 'executable', 'nobody', 'nobody_uid', 'os', 'select', 'sys', 'test', 'urllib']
dir函數會簡單的返回一個列表,其中包含啦帶屬性對象的全部屬性字符串名稱,這是一種在交互提示符下喚醒對模塊記憶的便捷方式。