{"id":1035256,"date":"2024-12-31T11:57:18","date_gmt":"2024-12-31T03:57:18","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1035256.html"},"modified":"2024-12-31T11:57:20","modified_gmt":"2024-12-31T03:57:20","slug":"python%e5%a6%82%e4%bd%95%e6%9f%a5%e7%9c%8b%e5%af%bc%e5%85%a5%e7%9a%84%e6%a8%a1%e5%9d%97%e5%92%8c%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1035256.html","title":{"rendered":"python\u5982\u4f55\u67e5\u770b\u5bfc\u5165\u7684\u6a21\u5757\u548c\u51fd\u6570"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/0a3fec98-99b6-4189-acb8-ca4b6a8834f6.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"python\u5982\u4f55\u67e5\u770b\u5bfc\u5165\u7684\u6a21\u5757\u548c\u51fd\u6570\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u67e5\u770b\u5bfc\u5165\u7684\u6a21\u5757\u548c\u51fd\u6570\u7684\u65b9\u6cd5\u6709\u4f7f\u7528\u5185\u7f6e\u51fd\u6570dir()\u3001\u901a\u8fc7inspect\u6a21\u5757\u83b7\u53d6\u8be6\u7ec6\u4fe1\u606f\u3001\u4f7f\u7528help()\u51fd\u6570\u8fdb\u884c\u5e2e\u52a9\u67e5\u770b\u3002<\/strong> \u5176\u4e2d\uff0c\u4f7f\u7528<code>dir()<\/code>\u51fd\u6570\u662f\u6700\u7b80\u5355\u548c\u76f4\u63a5\u7684\u65b9\u6cd5\uff0c\u5b83\u53ef\u4ee5\u5217\u51fa\u5f53\u524d\u4f5c\u7528\u57df\u4e2d\u7684\u6240\u6709\u53d8\u91cf\u3001\u51fd\u6570\u548c\u6a21\u5757\u3002\u4e0b\u9762\u6211\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\u6765\u67e5\u770b\u5bfc\u5165\u7684\u6a21\u5757\u548c\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528dir()\u51fd\u6570<\/h3>\n<\/p>\n<p><p><code>dir()<\/code>\u51fd\u6570\u662fPython\u5185\u7f6e\u7684\u51fd\u6570\uff0c\u53ef\u4ee5\u5217\u51fa\u6307\u5b9a\u6a21\u5757\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002\u4f7f\u7528<code>dir()<\/code>\u51fd\u6570\u53ef\u4ee5\u5feb\u901f\u67e5\u770b\u67d0\u4e2a\u6a21\u5757\u4e2d\u5305\u542b\u7684\u51fd\u6570\u548c\u53d8\u91cf\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>print(dir(math))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u8ff0\u4ee3\u7801\u5c06\u5217\u51famath\u6a21\u5757\u4e2d\u7684\u6240\u6709\u51fd\u6570\u548c\u53d8\u91cf\u3002\u8fd9\u4e9b\u51fd\u6570\u548c\u53d8\u91cf\u5305\u62ec\u4e86\u6570\u5b66\u76f8\u5173\u7684\u5e38\u89c1\u64cd\u4f5c\uff0c\u5982<code>sin()<\/code>\u3001<code>cos()<\/code>\u3001<code>tan()<\/code>\u4ee5\u53ca\u5e38\u91cf<code>pi<\/code>\u7b49\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528inspect\u6a21\u5757<\/h3>\n<\/p>\n<p><p><code>inspect<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u8bb8\u591a\u51fd\u6570\uff0c\u53ef\u4ee5\u5e2e\u52a9\u83b7\u53d6\u6709\u5173\u6a21\u5757\u3001\u51fd\u6570\u3001\u7c7b\u3001\u65b9\u6cd5\u7b49\u7684\u8be6\u7ec6\u4fe1\u606f\u3002\u4f7f\u7528<code>inspect<\/code>\u6a21\u5757\u53ef\u4ee5\u67e5\u770b\u5bfc\u5165\u6a21\u5757\u4e2d\u7684\u51fd\u6570\u7b7e\u540d\u3001\u6587\u6863\u5b57\u7b26\u4e32\u548c\u6e90\u4ee3\u7801\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import inspect<\/p>\n<p>import math<\/p>\n<h2><strong>\u83b7\u53d6math\u6a21\u5757\u4e2d\u7684\u6240\u6709\u6210\u5458<\/strong><\/h2>\n<p>members = inspect.getmembers(math)<\/p>\n<p>for member in members:<\/p>\n<p>    print(member)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u8ff0\u4ee3\u7801\u5c06\u5217\u51famath\u6a21\u5757\u4e2d\u7684\u6240\u6709\u6210\u5458\uff0c\u5305\u62ec\u51fd\u6570\u3001\u53d8\u91cf\u548c\u5e38\u91cf\u7b49\u3002<code>inspect.getmembers()<\/code>\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u6a21\u5757\u6210\u5458\u7684\u5217\u8868\uff0c\u6bcf\u4e2a\u6210\u5458\u662f\u4e00\u4e2a(name, value)\u5bf9\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528help()\u51fd\u6570<\/h3>\n<\/p>\n<p><p><code>help()<\/code>\u51fd\u6570\u662fPython\u5185\u7f6e\u7684\u5e2e\u52a9\u7cfb\u7edf\uff0c\u53ef\u4ee5\u63d0\u4f9b\u6709\u5173\u6a21\u5757\u3001\u51fd\u6570\u3001\u7c7b\u3001\u65b9\u6cd5\u7b49\u7684\u8be6\u7ec6\u6587\u6863\u3002\u5728\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u4e2d\uff0c\u8f93\u5165<code>help()<\/code>\u53ef\u4ee5\u542f\u52a8\u5e2e\u52a9\u7cfb\u7edf\uff0c\u8f93\u5165\u6a21\u5757\u540d\u6216\u51fd\u6570\u540d\u53ef\u4ee5\u83b7\u53d6\u8be6\u7ec6\u7684\u5e2e\u52a9\u4fe1\u606f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>help(math)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u8ff0\u4ee3\u7801\u5c06\u8f93\u51famath\u6a21\u5757\u7684\u8be6\u7ec6\u5e2e\u52a9\u4fe1\u606f\uff0c\u5305\u62ec\u6a21\u5757\u4e2d\u7684\u6240\u6709\u51fd\u6570\u3001\u53d8\u91cf\u548c\u5e38\u91cf\u7684\u63cf\u8ff0\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u901a\u8fc7\u6a21\u5757\u7684__all__\u5c5e\u6027<\/h3>\n<\/p>\n<p><p>\u6709\u4e9b\u6a21\u5757\u4f1a\u5b9a\u4e49\u4e00\u4e2a<code>__all__<\/code>\u5c5e\u6027\uff0c\u7528\u4e8e\u6307\u5b9a\u6a21\u5757\u7684\u516c\u5171\u63a5\u53e3\u3002\u5982\u679c\u6a21\u5757\u5b9a\u4e49\u4e86<code>__all__<\/code>\u5c5e\u6027\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95ee\u8be5\u5c5e\u6027\u6765\u83b7\u53d6\u6a21\u5757\u4e2d\u516c\u5f00\u7684\u51fd\u6570\u548c\u53d8\u91cf\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import some_module<\/p>\n<p>if hasattr(some_module, &#39;__all__&#39;):<\/p>\n<p>    print(some_module.__all__)<\/p>\n<p>else:<\/p>\n<p>    print(&quot;The module does not define __all__ attribute&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u8ff0\u4ee3\u7801\u5c06\u8f93\u51fasome_module\u6a21\u5757\u7684\u516c\u5171\u63a5\u53e3\uff08\u5982\u679c\u8be5\u6a21\u5757\u5b9a\u4e49\u4e86<code>__all__<\/code>\u5c5e\u6027\uff09\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\u67e5\u770b\u5bfc\u5165\u7684\u6a21\u5757\u548c\u51fd\u6570\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528\u5185\u7f6e\u51fd\u6570<code>dir()<\/code>\u3001\u901a\u8fc7<code>inspect<\/code>\u6a21\u5757\u83b7\u53d6\u8be6\u7ec6\u4fe1\u606f\u3001\u4f7f\u7528<code>help()<\/code>\u51fd\u6570\u8fdb\u884c\u5e2e\u52a9\u67e5\u770b\u4ee5\u53ca\u901a\u8fc7\u6a21\u5757\u7684<code>__all__<\/code>\u5c5e\u6027\u67e5\u770b\u516c\u5171\u63a5\u53e3\u3002<strong>\u4f7f\u7528<code>dir()<\/code>\u51fd\u6570\u662f\u6700\u7b80\u5355\u548c\u76f4\u63a5\u7684\u65b9\u6cd5<\/strong>\uff0c\u800c<code>inspect<\/code>\u6a21\u5757\u548c<code>help()<\/code>\u51fd\u6570\u53ef\u4ee5\u63d0\u4f9b\u66f4\u8be6\u7ec6\u7684\u4fe1\u606f\u3002\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u66f4\u597d\u5730\u4e86\u89e3\u548c\u4f7f\u7528\u5bfc\u5165\u7684\u6a21\u5757\u548c\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u8fdb\u4e00\u6b65\u5e94\u7528\u5b9e\u4f8b<\/h3>\n<\/p>\n<p><h4>1\u3001\u67e5\u770b\u81ea\u5b9a\u4e49\u6a21\u5757\u7684\u5185\u5bb9<\/h4>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u67e5\u770b\u81ea\u5b9a\u4e49\u6a21\u5757\u7684\u5185\u5bb9\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u540d\u4e3a<code>my_module.py<\/code>\u7684\u81ea\u5b9a\u4e49\u6a21\u5757\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u4e9b\u51fd\u6570\u548c\u53d8\u91cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># my_module.py<\/p>\n<p>def foo():<\/p>\n<p>    &quot;&quot;&quot;This is the foo function&quot;&quot;&quot;<\/p>\n<p>    pass<\/p>\n<p>def bar():<\/p>\n<p>    &quot;&quot;&quot;This is the bar function&quot;&quot;&quot;<\/p>\n<p>    pass<\/p>\n<p>baz = 42<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e0a\u8ff0\u65b9\u6cd5\u67e5\u770b<code>my_module<\/code>\u6a21\u5757\u7684\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import my_module<\/p>\n<p>import inspect<\/p>\n<h2><strong>\u4f7f\u7528dir()\u51fd\u6570<\/strong><\/h2>\n<p>print(dir(my_module))<\/p>\n<h2><strong>\u4f7f\u7528inspect\u6a21\u5757<\/strong><\/h2>\n<p>members = inspect.getmembers(my_module)<\/p>\n<p>for member in members:<\/p>\n<p>    print(member)<\/p>\n<h2><strong>\u4f7f\u7528help()\u51fd\u6570<\/strong><\/h2>\n<p>help(my_module)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u67e5\u770b\u7b2c\u4e09\u65b9\u5e93\u7684\u5185\u5bb9<\/h4>\n<\/p>\n<p><p>\u5728\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u65f6\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u4f7f\u7528\u76f8\u540c\u7684\u65b9\u6cd5\u67e5\u770b\u5e93\u4e2d\u7684\u6a21\u5757\u548c\u51fd\u6570\u3002\u4f8b\u5982\uff0c\u67e5\u770b<code>requests<\/code>\u5e93\u7684\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>import inspect<\/p>\n<h2><strong>\u4f7f\u7528dir()\u51fd\u6570<\/strong><\/h2>\n<p>print(dir(requests))<\/p>\n<h2><strong>\u4f7f\u7528inspect\u6a21\u5757<\/strong><\/h2>\n<p>members = inspect.getmembers(requests)<\/p>\n<p>for member in members:<\/p>\n<p>    print(member)<\/p>\n<h2><strong>\u4f7f\u7528help()\u51fd\u6570<\/strong><\/h2>\n<p>help(requests)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001\u6df1\u5165\u7406\u89e3inspect\u6a21\u5757<\/h3>\n<\/p>\n<p><p><code>inspect<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u8bb8\u591a\u6709\u7528\u7684\u51fd\u6570\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u6df1\u5165\u7406\u89e3\u6a21\u5757\u548c\u51fd\u6570\u7684\u7ed3\u6784\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684<code>inspect<\/code>\u6a21\u5757\u51fd\u6570\uff1a<\/p>\n<\/p>\n<ul>\n<li><code>inspect.getmembers(object, predicate=None)<\/code>: \u8fd4\u56de\u6307\u5b9a\u5bf9\u8c61\u7684\u6240\u6709\u6210\u5458\u3002<\/li>\n<li><code>inspect.ismodule(object)<\/code>: \u5982\u679c\u5bf9\u8c61\u662f\u6a21\u5757\uff0c\u8fd4\u56deTrue\u3002<\/li>\n<li><code>inspect.isclass(object)<\/code>: \u5982\u679c\u5bf9\u8c61\u662f\u7c7b\uff0c\u8fd4\u56deTrue\u3002<\/li>\n<li><code>inspect.isfunction(object)<\/code>: \u5982\u679c\u5bf9\u8c61\u662f\u51fd\u6570\uff0c\u8fd4\u56deTrue\u3002<\/li>\n<li><code>inspect.signature(callable)<\/code>: \u8fd4\u56de\u53ef\u8c03\u7528\u5bf9\u8c61\u7684\u7b7e\u540d\u3002<\/li>\n<\/ul>\n<p><p>\u901a\u8fc7\u8fd9\u4e9b\u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u7f16\u5199\u66f4\u590d\u6742\u7684\u4ee3\u7801\u6765\u5206\u6790\u6a21\u5757\u548c\u51fd\u6570\u3002\u4f8b\u5982\uff0c\u83b7\u53d6\u6a21\u5757\u4e2d\u7684\u6240\u6709\u51fd\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import inspect<\/p>\n<p>import my_module<\/p>\n<p>functions = inspect.getmembers(my_module, inspect.isfunction)<\/p>\n<p>for func in functions:<\/p>\n<p>    print(func)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516b\u3001\u52a8\u6001\u5206\u6790\u6a21\u5757<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u5728\u8fd0\u884c\u65f6\u52a8\u6001\u5206\u6790\u6a21\u5757\u548c\u51fd\u6570\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u52a8\u6001\u5bfc\u5165\u6a21\u5757\u5e76\u5206\u6790\u5176\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import importlib<\/p>\n<p>import inspect<\/p>\n<p>module_name = &#39;math&#39;<\/p>\n<p>module = importlib.import_module(module_name)<\/p>\n<h2><strong>\u83b7\u53d6\u6a21\u5757\u4e2d\u7684\u6240\u6709\u51fd\u6570<\/strong><\/h2>\n<p>functions = inspect.getmembers(module, inspect.isfunction)<\/p>\n<p>for func in functions:<\/p>\n<p>    print(func)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7279\u522b\u9002\u7528\u4e8e\u9700\u8981\u52a8\u6001\u52a0\u8f7d\u548c\u5206\u6790\u6a21\u5757\u7684\u573a\u666f\uff0c\u4f8b\u5982\u63d2\u4ef6\u7cfb\u7edf\u6216\u811a\u672c\u6267\u884c\u73af\u5883\u3002<\/p>\n<\/p>\n<p><h3>\u4e5d\u3001\u81ea\u52a8\u751f\u6210\u6587\u6863<\/h3>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e0a\u8ff0\u65b9\u6cd5\u81ea\u52a8\u751f\u6210\u6a21\u5757\u7684\u6587\u6863\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u4f7f\u7528<code>inspect<\/code>\u6a21\u5757\u751f\u6210\u6a21\u5757\u4e2d\u6240\u6709\u51fd\u6570\u7684\u6587\u6863\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import inspect<\/p>\n<p>import my_module<\/p>\n<p>functions = inspect.getmembers(my_module, inspect.isfunction)<\/p>\n<p>for func_name, func in functions:<\/p>\n<p>    doc = inspect.getdoc(func)<\/p>\n<p>    print(f&#39;Function: {func_name}\\nDocstring: {doc}\\n&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5341\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4f7f\u7528<code>dir()<\/code>\u51fd\u6570\u3001<code>inspect<\/code>\u6a21\u5757\u548c<code>help()<\/code>\u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u67e5\u770b\u5bfc\u5165\u7684\u6a21\u5757\u548c\u51fd\u6570\u7684\u5185\u5bb9\u3002<strong>\u8fd9\u4e9b\u65b9\u6cd5\u4e0d\u4ec5\u9002\u7528\u4e8e\u6807\u51c6\u5e93\u6a21\u5757\uff0c\u8fd8\u9002\u7528\u4e8e\u81ea\u5b9a\u4e49\u6a21\u5757\u548c\u7b2c\u4e09\u65b9\u5e93<\/strong>\u3002\u6df1\u5165\u7406\u89e3\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u66f4\u597d\u5730\u8c03\u8bd5\u548c\u5f00\u53d1Python\u4ee3\u7801\uff0c\u5e76\u81ea\u52a8\u751f\u6210\u6587\u6863\u548c\u52a8\u6001\u5206\u6790\u6a21\u5757\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5217\u51fa\u5df2\u5bfc\u5165\u7684\u6a21\u5757\u548c\u51fd\u6570\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684<code>sys<\/code>\u6a21\u5757\u6765\u67e5\u770b\u5df2\u5bfc\u5165\u7684\u6a21\u5757\u3002\u901a\u8fc7<code>sys.modules<\/code>\u53ef\u4ee5\u83b7\u53d6\u5f53\u524d\u6240\u6709\u5df2\u5bfc\u5165\u7684\u6a21\u5757\u7684\u5b57\u5178\uff0c\u5b57\u5178\u7684\u952e\u662f\u6a21\u5757\u540d\uff0c\u503c\u662f\u6a21\u5757\u5bf9\u8c61\u3002\u8981\u67e5\u770b\u7279\u5b9a\u6a21\u5757\u4e2d\u7684\u51fd\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528<code>dir()<\/code>\u51fd\u6570\uff0c\u8fd9\u4e2a\u51fd\u6570\u4f1a\u5217\u51fa\u6a21\u5757\u4e2d\u6240\u6709\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\uff0c\u5305\u62ec\u51fd\u6570\u3002<\/p>\n<p><strong>\u4f7f\u7528\u54ea\u4e9b\u5de5\u5177\u53ef\u4ee5\u66f4\u65b9\u4fbf\u5730\u67e5\u770b\u6a21\u5757\u548c\u51fd\u6570\uff1f<\/strong><br \/>\u9664\u4e86\u624b\u52a8\u7f16\u5199\u4ee3\u7801\u5916\uff0c\u8fd8\u6709\u4e00\u4e9b\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5feb\u901f\u67e5\u770b\u5bfc\u5165\u7684\u6a21\u5757\u548c\u51fd\u6570\u3002\u4f8b\u5982\uff0c<code>IPython<\/code>\u548c<code>Jupyter Notebook<\/code>\u90fd\u63d0\u4f9b\u4e86\u589e\u5f3a\u7684\u4ea4\u4e92\u5f0f\u73af\u5883\uff0c\u53ef\u4ee5\u4f7f\u7528<code>?<\/code>\u6216<code>??<\/code>\u6765\u67e5\u770b\u6a21\u5757\u548c\u51fd\u6570\u7684\u8be6\u7ec6\u4fe1\u606f\u3002\u6b64\u5916\uff0c<code>help()<\/code>\u51fd\u6570\u4e5f\u80fd\u63d0\u4f9b\u6a21\u5757\u53ca\u5176\u529f\u80fd\u7684\u6587\u6863\u3002<\/p>\n<p><strong>\u5982\u4f55\u786e\u8ba4\u5bfc\u5165\u7684\u6a21\u5757\u662f\u5426\u5df2\u6210\u529f\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7<code>import<\/code>\u8bed\u53e5\u5bfc\u5165\u6a21\u5757\u540e\uff0c\u76f4\u63a5\u4f7f\u7528\u6a21\u5757\u7684\u540d\u79f0\u6765\u9a8c\u8bc1\u5176\u662f\u5426\u5df2\u6210\u529f\u5bfc\u5165\u3002\u5982\u679c\u6a21\u5757\u5bfc\u5165\u6210\u529f\uff0cPython\u4e0d\u4f1a\u629b\u51fa\u9519\u8bef\u3002\u6b64\u5916\uff0c\u53ef\u4ee5\u4f7f\u7528<code>print()<\/code>\u51fd\u6570\u8f93\u51fa\u6a21\u5757\u7684\u67d0\u4e2a\u5c5e\u6027\u6216\u65b9\u6cd5\uff0c\u5982\u679c\u6ca1\u6709\u9519\u8bef\u4fe1\u606f\u4e14\u80fd\u6b63\u5e38\u8f93\u51fa\uff0c\u5219\u8bf4\u660e\u6a21\u5757\u5df2\u6210\u529f\u5bfc\u5165\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u67e5\u770b\u5bfc\u5165\u7684\u6a21\u5757\u548c\u51fd\u6570\u7684\u65b9\u6cd5\u6709\u4f7f\u7528\u5185\u7f6e\u51fd\u6570dir()\u3001\u901a\u8fc7inspect\u6a21\u5757\u83b7\u53d6\u8be6\u7ec6\u4fe1\u606f\u3001\u4f7f\u7528h [&hellip;]","protected":false},"author":3,"featured_media":1035263,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1035256"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1035256"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1035256\/revisions"}],"predecessor-version":[{"id":1035265,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1035256\/revisions\/1035265"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1035263"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1035256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1035256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1035256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}