{"id":963204,"date":"2024-12-27T04:15:37","date_gmt":"2024-12-26T20:15:37","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/963204.html"},"modified":"2024-12-27T04:15:40","modified_gmt":"2024-12-26T20:15:40","slug":"python%e5%a6%82%e4%bd%95%e6%9f%a5%e7%9c%8b%e5%86%85%e9%83%a8%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/963204.html","title":{"rendered":"python\u5982\u4f55\u67e5\u770b\u5185\u90e8\u51fd\u6570"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24180626\/7c584dab-a6c5-4f0d-83ef-dd2291e1742a.webp\" alt=\"python\u5982\u4f55\u67e5\u770b\u5185\u90e8\u51fd\u6570\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u67e5\u770b\u5185\u90e8\u51fd\u6570\u7684\u5e38\u7528\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528<code>dir()<\/code>\u51fd\u6570\u3001\u67e5\u770b\u6a21\u5757\u7684\u6587\u6863\u5b57\u7b26\u4e32\u3001\u901a\u8fc7<code>inspect<\/code>\u6a21\u5757\u8fdb\u884c\u67e5\u770b<\/strong>\u3002\u5176\u4e2d\uff0c\u4f7f\u7528<code>inspect<\/code>\u6a21\u5757\u662f\u6700\u8be6\u7ec6\u548c\u4e13\u4e1a\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u63d0\u4f9b\u5173\u4e8e\u51fd\u6570\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u5982\u51fd\u6570\u7b7e\u540d\u3001\u6587\u6863\u5b57\u7b26\u4e32\u7b49\u3002<\/p>\n<\/p>\n<p><p>Python\u662f\u4e00\u79cd\u52a8\u6001\u8bed\u8a00\uff0c\u62e5\u6709\u5f3a\u5927\u7684\u53cd\u5c04\u80fd\u529b\uff0c\u8fd9\u4f7f\u5f97\u5f00\u53d1\u8005\u53ef\u4ee5\u5728\u8fd0\u884c\u65f6\u67e5\u770b\u5bf9\u8c61\u7684\u5185\u90e8\u7ed3\u6784\u548c\u7279\u6027\u3002\u4e86\u89e3\u5982\u4f55\u67e5\u770b\u5185\u90e8\u51fd\u6570\u5bf9\u4e8e\u8c03\u8bd5\u3001\u5b66\u4e60\u548c\u4ee3\u7801\u7406\u89e3\u975e\u5e38\u6709\u5e2e\u52a9\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7\u4e0a\u8ff0\u65b9\u6cd5\u67e5\u770bPython\u5185\u90e8\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u4f7f\u7528<code>dir()<\/code>\u51fd\u6570<\/h2>\n<\/p>\n<p><p><code>dir()<\/code>\u51fd\u6570\u662f\u4e00\u4e2a\u5185\u7f6e\u51fd\u6570\uff0c\u7528\u4e8e\u5217\u51fa\u5bf9\u8c61\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\uff0c\u5305\u62ec\u5185\u90e8\u51fd\u6570\u3002\u5bf9\u4e8e\u4e00\u4e2a\u6a21\u5757\u6216\u7c7b\uff0c<code>dir()<\/code>\u4f1a\u8fd4\u56de\u5176\u6240\u6709\u53ef\u7528\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528\u65b9\u6cd5<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u67e5\u770b\u6a21\u5757\u4e2d\u7684\u51fd\u6570\u548c\u5c5e\u6027\uff1a<\/strong><\/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>\u8fd9\u5c06\u5217\u51fa<code>math<\/code>\u6a21\u5757\u4e2d\u7684\u6240\u6709\u51fd\u6570\u548c\u5c5e\u6027\uff0c\u5305\u62ec\u5185\u90e8\u51fd\u6570\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u67e5\u770b\u7c7b\u4e2d\u7684\u65b9\u6cd5\u548c\u5c5e\u6027\uff1a<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class SampleClass:<\/p>\n<p>    def method_one(self):<\/p>\n<p>        pass<\/p>\n<p>    def method_two(self):<\/p>\n<p>        pass<\/p>\n<p>print(dir(SampleClass))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6b64\u4ee3\u7801\u6bb5\u4f1a\u663e\u793a<code>SampleClass<\/code>\u7c7b\u4e2d\u7684\u6240\u6709\u65b9\u6cd5\u548c\u5c5e\u6027\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u9650\u5236<\/h3>\n<\/p>\n<p><p><code>dir()<\/code>\u51fd\u6570\u4ec5\u663e\u793a\u540d\u79f0\u5217\u8868\uff0c\u5e76\u4e0d\u63d0\u4f9b\u5173\u4e8e\u6bcf\u4e2a\u51fd\u6570\u6216\u5c5e\u6027\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u5982\u53c2\u6570\u3001\u8fd4\u56de\u503c\u7b49\u3002\u56e0\u6b64\uff0c\u5b83\u9002\u5408\u5feb\u901f\u67e5\u770b\u5bf9\u8c61\u7684\u7ed3\u6784\uff0c\u4f46\u4e0d\u9002\u5408\u6df1\u5165\u5206\u6790\u3002<\/p>\n<\/p>\n<p><h2>\u4e8c\u3001\u67e5\u770b\u6a21\u5757\u7684\u6587\u6863\u5b57\u7b26\u4e32<\/h2>\n<\/p>\n<p><p>Python\u4e2d\u7684\u6a21\u5757\u548c\u51fd\u6570\u901a\u5e38\u4f1a\u5305\u542b\u6587\u6863\u5b57\u7b26\u4e32\uff08docstring\uff09\uff0c\u5b83\u4eec\u63d0\u4f9b\u4e86\u4f7f\u7528\u8bf4\u660e\u548c\u53c2\u6570\u63cf\u8ff0\u3002\u901a\u8fc7\u67e5\u770b\u6587\u6863\u5b57\u7b26\u4e32\uff0c\u53ef\u4ee5\u4e86\u89e3\u5185\u90e8\u51fd\u6570\u7684\u7528\u9014\u548c\u4f7f\u7528\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528\u65b9\u6cd5<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u67e5\u770b\u6a21\u5757\u7684\u6587\u6863\uff1a<\/strong><\/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>\u4f7f\u7528<code>help()<\/code>\u51fd\u6570\u53ef\u4ee5\u67e5\u770b<code>math<\/code>\u6a21\u5757\u7684\u8be6\u7ec6\u6587\u6863\uff0c\u5305\u62ec\u6bcf\u4e2a\u51fd\u6570\u7684\u8bf4\u660e\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u67e5\u770b\u51fd\u6570\u7684\u6587\u6863\uff1a<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def sample_function():<\/p>\n<p>    &quot;&quot;&quot;This is a sample function.&quot;&quot;&quot;<\/p>\n<p>    pass<\/p>\n<p>print(sample_function.__doc__)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7<code>__doc__<\/code>\u5c5e\u6027\uff0c\u53ef\u4ee5\u76f4\u63a5\u8bbf\u95ee\u51fd\u6570\u7684\u6587\u6863\u5b57\u7b26\u4e32\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u9650\u5236<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u6a21\u5757\u6216\u51fd\u6570\u6ca1\u6709\u63d0\u4f9b\u6587\u6863\u5b57\u7b26\u4e32\uff0c\u5219\u65e0\u6cd5\u901a\u8fc7\u8fd9\u79cd\u65b9\u6cd5\u83b7\u53d6\u8be6\u7ec6\u4fe1\u606f\u3002\u6b64\u5916\uff0c\u6587\u6863\u5b57\u7b26\u4e32\u7684\u8be6\u7ec6\u7a0b\u5ea6\u4f9d\u8d56\u4e8e\u7f16\u5199\u8005\u7684\u6587\u6863\u4e60\u60ef\u3002<\/p>\n<\/p>\n<p><h2>\u4e09\u3001\u4f7f\u7528<code>inspect<\/code>\u6a21\u5757<\/h2>\n<\/p>\n<p><p><code>inspect<\/code>\u6a21\u5757\u662fPython\u6807\u51c6\u5e93\u7684\u4e00\u90e8\u5206\uff0c\u63d0\u4f9b\u4e86\u591a\u79cd\u51fd\u6570\uff0c\u7528\u4e8e\u83b7\u53d6\u5173\u4e8e\u5bf9\u8c61\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u5982\u7b7e\u540d\u3001\u6e90\u4ee3\u7801\u3001\u6587\u6863\u5b57\u7b26\u4e32\u7b49\u3002\u5b83\u662f\u67e5\u770b\u5185\u90e8\u51fd\u6570\u6700\u4e13\u4e1a\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528\u65b9\u6cd5<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u83b7\u53d6\u51fd\u6570\u7b7e\u540d\uff1a<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import inspect<\/p>\n<p>def sample_function(param1, param2):<\/p>\n<p>    &quot;&quot;&quot;This is a sample function.&quot;&quot;&quot;<\/p>\n<p>    return param1 + param2<\/p>\n<p>signature = inspect.signature(sample_function)<\/p>\n<p>print(signature)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u8f93\u51fa\u51fd\u6570\u7684\u7b7e\u540d\u4fe1\u606f\uff0c\u5305\u62ec\u53c2\u6570\u540d\u548c\u9ed8\u8ba4\u503c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u83b7\u53d6\u51fd\u6570\u7684\u6e90\u4ee3\u7801\uff1a<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import inspect<\/p>\n<p>def sample_function(param1, param2):<\/p>\n<p>    &quot;&quot;&quot;This is a sample function.&quot;&quot;&quot;<\/p>\n<p>    return param1 + param2<\/p>\n<p>source = inspect.getsource(sample_function)<\/p>\n<p>print(source)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528<code>getsource()<\/code>\u51fd\u6570\u53ef\u4ee5\u83b7\u53d6\u51fd\u6570\u7684\u6e90\u4ee3\u7801\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u83b7\u53d6\u6a21\u5757\u7684\u6240\u6709\u6210\u5458\uff1a<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import inspect<\/p>\n<p>import math<\/p>\n<p>for name, obj in inspect.getmembers(math):<\/p>\n<p>    if inspect.isfunction(obj):<\/p>\n<p>        print(name)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7<code>getmembers()<\/code>\u51fd\u6570\uff0c\u53ef\u4ee5\u83b7\u53d6\u6a21\u5757\u7684\u6240\u6709\u6210\u5458\uff0c\u5e76\u8fc7\u6ee4\u51fa\u51fd\u6570\u7c7b\u578b\u7684\u6210\u5458\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4f18\u52bf<\/h3>\n<\/p>\n<p><p><code>inspect<\/code>\u6a21\u5757\u4e0d\u4ec5\u80fd\u591f\u63d0\u4f9b\u8be6\u7ec6\u7684\u51fd\u6570\u4fe1\u606f\uff0c\u8fd8\u80fd\u652f\u6301\u52a8\u6001\u5206\u6790\uff0c\u8fd9\u5bf9\u4e8e\u5927\u578b\u9879\u76ee\u7684\u8c03\u8bd5\u548c\u5206\u6790\u975e\u5e38\u6709\u7528\u3002\u901a\u8fc7<code>inspect<\/code>\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u5168\u9762\u4e86\u89e3\u6a21\u5757\u548c\u51fd\u6570\u7684\u5185\u90e8\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><h2>\u56db\u3001\u4f7f\u7528IPython\u548cJupyter Notebook<\/h2>\n<\/p>\n<p><p>IPython\u548cJupyter Notebook\u662fPython\u7684\u9ad8\u7ea7\u4ea4\u4e92\u73af\u5883\uff0c\u5b83\u4eec\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5de5\u5177\u7528\u4e8e\u67e5\u770b\u548c\u5206\u6790\u5bf9\u8c61\u7684\u7ed3\u6784\u548c\u6587\u6863\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528\u65b9\u6cd5<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528<code>?<\/code>\u67e5\u770b\u5bf9\u8c61\u4fe1\u606f\uff1a<\/strong><\/p>\n<\/p>\n<p><p>\u5728IPython\u6216Jupyter Notebook\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>?<\/code>\u6765\u67e5\u770b\u5bf9\u8c61\u7684\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>math.sin?<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u663e\u793a<code>sin<\/code>\u51fd\u6570\u7684\u6587\u6863\u5b57\u7b26\u4e32\u548c\u7b7e\u540d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528<code>??<\/code>\u67e5\u770b\u5bf9\u8c61\u6e90\u4ee3\u7801\uff1a<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>math.sin??<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u6e90\u4ee3\u7801\u53ef\u7528\uff0c<code>??<\/code>\u5c06\u663e\u793a\u51fd\u6570\u7684\u6e90\u4ee3\u7801\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4f18\u52bf<\/h3>\n<\/p>\n<p><p>IPython\u548cJupyter Notebook\u63d0\u4f9b\u4e86\u4ea4\u4e92\u5f0f\u7684\u5f00\u53d1\u73af\u5883\uff0c\u5141\u8bb8\u5f00\u53d1\u8005\u5b9e\u65f6\u67e5\u770b\u548c\u5206\u6790\u4ee3\u7801\u3002\u8fd9\u5bf9\u4e8e\u6570\u636e\u79d1\u5b66\u548c<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u9879\u76ee\u5c24\u5176\u6709\u7528\uff0c\u56e0\u4e3a\u5b83\u4eec\u901a\u5e38\u9700\u8981\u9891\u7e41\u6d4b\u8bd5\u548c\u5206\u6790\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h2>\u4e94\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u548c\u5de5\u5177<\/h2>\n<\/p>\n<p><p>\u9664\u4e86Python\u6807\u51c6\u5e93\u548c\u5185\u7f6e\u5de5\u5177\u5916\uff0c\u8fd8\u6709\u4e00\u4e9b\u7b2c\u4e09\u65b9\u5e93\u548c\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u67e5\u770b\u548c\u5206\u6790\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528\u65b9\u6cd5<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528PyCharm\u7b49IDE\uff1a<\/strong><\/p>\n<\/p>\n<p><p>PyCharm\u7b49\u96c6\u6210\u5f00\u53d1\u73af\u5883\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u4ee3\u7801\u5bfc\u822a\u548c\u5206\u6790\u5de5\u5177\uff0c\u5141\u8bb8\u5f00\u53d1\u8005\u8f7b\u677e\u67e5\u770b\u51fd\u6570\u7684\u5b9a\u4e49\u3001\u8c03\u7528\u5173\u7cfb\u548c\u6587\u6863\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528pydoc\u751f\u6210\u6587\u6863\uff1a<\/strong><\/p>\n<\/p>\n<p><p><code>pydoc<\/code>\u662fPython\u81ea\u5e26\u7684\u6587\u6863\u751f\u6210\u5de5\u5177\uff0c\u53ef\u4ee5\u751f\u6210\u6a21\u5757\u548c\u51fd\u6570\u7684HTML\u6587\u6863\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pydoc -w math<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u751f\u6210<code>math<\/code>\u6a21\u5757\u7684HTML\u6587\u6863\uff0c\u5305\u542b\u6240\u6709\u51fd\u6570\u7684\u8be6\u7ec6\u4fe1\u606f\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4f18\u52bf<\/h3>\n<\/p>\n<p><p>\u7b2c\u4e09\u65b9\u5de5\u5177\u901a\u5e38\u63d0\u4f9b\u4e86\u66f4\u53cb\u597d\u7684\u7528\u6237\u754c\u9762\u548c\u66f4\u591a\u7684\u529f\u80fd\uff0c\u9002\u5408\u4e8e\u5927\u578b\u9879\u76ee\u7684\u5f00\u53d1\u548c\u7ef4\u62a4\u3002<\/p>\n<\/p>\n<p><p>\u7efc\u4e0a\u6240\u8ff0\uff0cPython\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u6765\u67e5\u770b\u548c\u5206\u6790\u5185\u90e8\u51fd\u6570\uff0c\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u4f18\u7f3a\u70b9\u3002\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u66f4\u597d\u5730\u7406\u89e3\u548c\u4f7f\u7528Python\u4ee3\u7801\u3002\u65e0\u8bba\u662f\u901a\u8fc7\u5185\u7f6e\u51fd\u6570\u3001\u6807\u51c6\u5e93\u8fd8\u662f\u7b2c\u4e09\u65b9\u5de5\u5177\uff0c\u638c\u63e1\u8fd9\u4e9b\u6280\u80fd\u90fd\u80fd\u663e\u8457\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u4ee3\u7801\u8d28\u91cf\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u67e5\u770b\u4e00\u4e2a\u6a21\u5757\u6216\u7c7b\u7684\u5185\u90e8\u51fd\u6570\uff1f<\/strong><br \/>\u60a8\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684<code>dir()<\/code>\u51fd\u6570\u6765\u5217\u51fa\u6a21\u5757\u6216\u7c7b\u4e2d\u7684\u6240\u6709\u5c5e\u6027\u548c\u65b9\u6cd5\uff0c\u5305\u62ec\u5185\u90e8\u51fd\u6570\u3002\u53ea\u9700\u5c06\u6a21\u5757\u6216\u7c7b\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9<code>dir()<\/code>\uff0c\u5b83\u5c06\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u6240\u6709\u6210\u5458\u540d\u79f0\u7684\u5217\u8868\u3002\u6b64\u5916\uff0c\u4f7f\u7528<code>help()<\/code>\u51fd\u6570\u53ef\u4ee5\u83b7\u53d6\u66f4\u8be6\u7ec6\u7684\u4fe1\u606f\uff0c\u67e5\u770b\u51fd\u6570\u7684\u6587\u6863\u5b57\u7b26\u4e32\u3002<\/p>\n<p><strong>\u662f\u5426\u53ef\u4ee5\u901a\u8fc7\u53cd\u5c04\u673a\u5236\u6765\u8bbf\u95eePython\u5bf9\u8c61\u7684\u5185\u90e8\u51fd\u6570\uff1f<\/strong><br \/>\u662f\u7684\uff0cPython\u652f\u6301\u53cd\u5c04\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>getattr()<\/code>\u51fd\u6570\u6765\u8bbf\u95ee\u5bf9\u8c61\u7684\u5185\u90e8\u51fd\u6570\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7<code>getattr(obj, &#39;function_name&#39;)<\/code>\u6765\u83b7\u53d6\u6307\u5b9a\u540d\u79f0\u7684\u51fd\u6570\u5bf9\u8c61\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u52a8\u6001\u8bbf\u95ee\u548c\u8c03\u7528\u51fd\u6570\u3002<\/p>\n<p><strong>\u6709\u54ea\u4e9b\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u6211\u66f4\u8f7b\u677e\u5730\u67e5\u770bPython\u4ee3\u7801\u4e2d\u7684\u5185\u90e8\u51fd\u6570\uff1f<\/strong><br \/>\u6709\u8bb8\u591a\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u60a8\u67e5\u770b\u548c\u5206\u6790Python\u4ee3\u7801\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528IDE\uff08\u5982PyCharm\u6216VSCode\uff09\u4e2d\u7684\u4ee3\u7801\u5bfc\u822a\u529f\u80fd\uff0c\u5feb\u901f\u8df3\u8f6c\u5230\u51fd\u6570\u5b9a\u4e49\u3002\u6b64\u5916\uff0c\u4f7f\u7528<code>pydoc<\/code>\u547d\u4ee4\u884c\u5de5\u5177\u53ef\u4ee5\u751f\u6210\u6a21\u5757\u7684\u6587\u6863\uff0c\u5e2e\u52a9\u60a8\u4e86\u89e3\u5404\u4e2a\u51fd\u6570\u7684\u7528\u9014\u548c\u53c2\u6570\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u67e5\u770b\u5185\u90e8\u51fd\u6570\u7684\u5e38\u7528\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528dir()\u51fd\u6570\u3001\u67e5\u770b\u6a21\u5757\u7684\u6587\u6863\u5b57\u7b26\u4e32\u3001\u901a\u8fc7inspect\u6a21\u5757\u8fdb [&hellip;]","protected":false},"author":3,"featured_media":963212,"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\/963204"}],"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=963204"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/963204\/revisions"}],"predecessor-version":[{"id":963213,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/963204\/revisions\/963213"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/963212"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=963204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=963204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=963204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}