2017-03-08 24 views
-1

我想知道當我給出dir(sys)作爲示例時所列項目的術語。python中的術語和用法

會更清楚,我們將如何參考這些call_tracing或callstarts或copyright。他們會被稱爲「方法」嗎?我們如何知道該目錄列表中每個屬性的用法?

>>>import sys 
>>>dir(sys) 

['__displayhook__', '__doc__', '__excepthook__', '__name__', '__package__', '__stderr__', '__stdin__', '__stdout__', '_clear_type_cache', '_current_frames', '_getframe', '_mercurial', 'api_version', 'argv', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook', 'dllhandle', 'dont_write_bytecode', 'exc_clear', 'exc_info', 'exc_traceback', 'exc_type', 'exc_value', 'excepthook', 'exec_prefix', 'executable', 'exit', 'flags', 'float_info', 'float_repr_style', 'getcheckinterval', 'getdefaultencoding', 'getfilesystemencoding', 'getprofile', 'getrecursionlimit', 'getrefcount', 'getsizeof', 'gettrace', 'getwindowsversion', 'hexversion', 'last_traceback', 'last_type', 'last_value', 'long_info', 'maxint', 'maxsize', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'py3kwarning', 'setcheckinterval', 'setprofile', 'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'subversion', 'version', 'version_info', 'warnoptions', 'winver'] 
+0

https://docs.python.org/2/library/ –

+0

爲什麼不在shell的列表中鍵入'sys.call_tracing','sys.callstats'或任何東西來查看它們的類型是什麼?如果它是一個功能。你會得到''之類的東西 – TidB

回答

1

通常,dir(...)命令將顯示一個類中存在的所有屬性的列表。例如sys模塊的屬性爲'__displayhook__', '__doc__', '__excepthook__', '__name__', etc

如果我正確理解你的問題,那麼,他們將被稱爲上的方法,你的情況,其中包含call_tracingcallstartscopyright方法sys模塊。

有關每個類的屬性使用情況的信息,您將不得不參考該模塊的文檔。你提到的sys模塊可以找到here

有關dir()命令的更多信息,您可以閱讀文檔here