欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

【python3】查看模块及包含的方法

时间:2023-05-20

dir:查看模块中的方法

import sysprint(dir(sys))​输出:In [11]: print(dir(sys))['__breakpointhook__', '__displayhook__', '__doc__', '__excepthook__', '__interactivehook__', '__loader__', '__name__', '__package__', '__spec__', '__stderr__', '__stdin__', '__stdout__', '__unraisablehook__', '_base_executable', '_clear_type_cache', '_current_frames', '_debugmallocstats', '_framework', '_getframe', '_git', '_home', '_xoptions', 'abiflags', 'addaudithook', 'api_version', 'argv', 'audit', 'base_exec_prefix', 'base_prefix', 'breakpointhook', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook', 'dont_write_bytecode', 'exc_info', 'excepthook', 'exec_prefix', 'executable', 'exit', 'flags', 'float_info', 'float_repr_style', 'get_asyncgen_hooks', 'get_coroutine_origin_tracking_depth', 'getallocatedblocks', 'getcheckinterval', 'getdefaultencoding', 'getdlopenflags', 'getfilesystemencodeerrors', 'getfilesystemencoding', 'getprofile', 'getrecursionlimit', 'getrefcount', 'getsizeof', 'getswitchinterval', 'gettrace', 'hash_info', 'hexversion', 'implementation', 'int_info', 'intern', 'is_finalizing', 'last_traceback', 'last_type', 'last_value', 'maxsize', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'ps1', 'ps2', 'ps3', 'pycache_prefix', 'set_asyncgen_hooks', 'set_coroutine_origin_tracking_depth', 'setcheckinterval', 'setdlopenflags', 'setprofile', 'setrecursionlimit', 'setswitchinterval', 'settrace', 'stderr', 'stdin', 'stdout', 'thread_info', 'unraisablehook', 'version', 'version_info', 'warnoptions']

help:查看模块或方法的内容

In [12]: print(help(sys))  # 也可以:In [13]: help()​help> sys​help> quit​​​# 输出:Help on built-in module sys:​NAME    sys​MODULE REFERENCE    https://docs.python.org/3.8/library/sys​    The following documentation is automatically generated from the Python    source files、 It may be incomplete, incorrect or include features that    are considered implementation detail and may vary between Python    implementations、 When in doubt, consult the module reference at the    location listed above.​DEscriptION    This module provides access to some objects used or maintained by the    interpreter and to functions that interact strongly with the interpreter.​    Dynamic objects:​    argv -- command line arguments; argv[0] is the script pathname if known    path -- module search path; path[0] is the script directory, else ''    modules -- dictionary of loaded modules​    displayhook -- called to show results in an interactive session    excepthook -- called to handle any uncaught exception other than SystemExit      To customize printing in an interactive session or to install a custom      top-level exception handler, assign other functions to replace these.

查看模块是内置还是外置

In [7]: import requests​In [8]: requestsOut[8]: ​In [9]: import sys​In [10]: sysOut[10]:

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。