{"id":1006577,"date":"2024-12-27T10:45:41","date_gmt":"2024-12-27T02:45:41","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1006577.html"},"modified":"2024-12-27T10:45:44","modified_gmt":"2024-12-27T02:45:44","slug":"python-%e5%a6%82%e4%bd%95%e6%9f%a5%e7%9c%8b%e6%96%87%e6%a1%a3%e5%86%85%e5%ae%b9","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1006577.html","title":{"rendered":"python \u5982\u4f55\u67e5\u770b\u6587\u6863\u5185\u5bb9"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25082639\/e21718fe-6d32-428c-9dbd-6436a154bde7.webp\" alt=\"python \u5982\u4f55\u67e5\u770b\u6587\u6863\u5185\u5bb9\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u67e5\u770b\u6587\u6863\u5185\u5bb9\u7684\u5e38\u7528\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528<code>help()<\/code>\u51fd\u6570\u3001<code>dir()<\/code>\u51fd\u6570\u3001\u67e5\u770b\u6a21\u5757\u7684<code>__doc__<\/code>\u5c5e\u6027\u3001\u5728\u7ebf\u6587\u6863\u3001\u4ee5\u53ca\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u4e2d\u7684\u81ea\u52a8\u8865\u5168\u548c\u6587\u6863\u67e5\u770b\u529f\u80fd\u3002<\/strong>\u5bf9\u4e8e\u521d\u5b66\u8005\u6765\u8bf4\uff0c\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u4f7f\u7528Python\u5185\u7f6e\u7684<code>help()<\/code>\u51fd\u6570\u548c<code>dir()<\/code>\u51fd\u6570\u3002<code>help()<\/code>\u51fd\u6570\u53ef\u4ee5\u63d0\u4f9b\u6a21\u5757\u3001\u7c7b\u3001\u65b9\u6cd5\u6216\u51fd\u6570\u7684\u8be6\u7ec6\u6587\u6863\uff0c\u800c<code>dir()<\/code>\u51fd\u6570\u5219\u53ef\u4ee5\u5217\u51fa\u6a21\u5757\u6216\u5bf9\u8c61\u7684\u6240\u6709\u5c5e\u6027\u548c\u65b9\u6cd5\u3002\u9664\u6b64\u4e4b\u5916\uff0c\u67e5\u770b\u6a21\u5757\u7684<code>__doc__<\/code>\u5c5e\u6027\u4e5f\u662f\u83b7\u53d6\u6587\u6863\u7684\u76f4\u63a5\u65b9\u5f0f\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528<code>help()<\/code>\u51fd\u6570<\/p>\n<\/p>\n<p><p><code>help()<\/code>\u51fd\u6570\u662fPython\u5185\u7f6e\u7684\u4e00\u4e2a\u51fd\u6570\uff0c\u7528\u4e8e\u67e5\u770b\u5bf9\u8c61\u7684\u6587\u6863\u5b57\u7b26\u4e32\u3002\u5b83\u662f\u83b7\u53d6\u6587\u6863\u4fe1\u606f\u7684\u6700\u76f4\u63a5\u65b9\u5f0f\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u67e5\u770b\u6a21\u5757\u6587\u6863<\/strong><\/p>\n<\/p>\n<p><p>\u8981\u67e5\u770b\u67d0\u4e2a\u6a21\u5757\u7684\u6587\u6863\uff0c\u53ef\u4ee5\u5728Python\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>help(os)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u663e\u793a<code>os<\/code>\u6a21\u5757\u7684\u8be6\u7ec6\u6587\u6863\uff0c\u5305\u62ec\u6a21\u5757\u4e2d\u7684\u7c7b\u3001\u51fd\u6570\u548c\u53d8\u91cf\u7684\u63cf\u8ff0\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u67e5\u770b\u51fd\u6570\u6216\u7c7b\u7684\u6587\u6863<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u60a8\u60f3\u67e5\u770b\u67d0\u4e2a\u51fd\u6570\u6216\u7c7b\u7684\u6587\u6863\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f20\u9012\u8be5\u51fd\u6570\u6216\u7c7b\u7ed9<code>help()<\/code>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">help(os.path.join)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u901a\u8fc7\u547d\u4ee4\u884c\u67e5\u770b<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\uff0c\u60a8\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884cPython\u5e76\u5728\u5176\u4e2d\u4f7f\u7528<code>help()<\/code>\uff0c\u8fd9\u4e0e\u5728Python\u811a\u672c\u4e2d\u4f7f\u7528\u6ca1\u6709\u533a\u522b\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u4f7f\u7528<code>dir()<\/code>\u51fd\u6570<\/p>\n<\/p>\n<p><p><code>dir()<\/code>\u51fd\u6570\u7528\u4e8e\u8fd4\u56de\u4e00\u4e2a\u6a21\u5757\u3001\u5bf9\u8c61\u7b49\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u5217\u8868\u3002\u5b83\u4e0d\u63d0\u4f9b\u8be6\u7ec6\u7684\u6587\u6863\uff0c\u800c\u662f\u8ba9\u60a8\u77e5\u9053\u53ef\u4ee5\u8bbf\u95ee\u54ea\u4e9b\u5c5e\u6027\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u67e5\u770b\u6a21\u5757\u7684\u5c5e\u6027\u548c\u65b9\u6cd5<\/strong><\/p>\n<\/p>\n<p><p>\u60a8\u53ef\u4ee5\u4f7f\u7528<code>dir()<\/code>\u51fd\u6570\u67e5\u770b\u6a21\u5757\u4e2d\u53ef\u7528\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">dir(os)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7ed3\u5408\u4f7f\u7528<code>help()<\/code>\u548c<code>dir()<\/code><\/strong><\/p>\n<\/p>\n<p><p>\u53ef\u4ee5\u5148\u7528<code>dir()<\/code>\u67e5\u770b\u6709\u54ea\u4e9b\u65b9\u6cd5\u6216\u5c5e\u6027\uff0c\u7136\u540e\u5bf9\u611f\u5174\u8da3\u7684\u90e8\u5206\u4f7f\u7528<code>help()<\/code>\u83b7\u53d6\u8be6\u7ec6\u4fe1\u606f\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u67e5\u770b<code>__doc__<\/code>\u5c5e\u6027<\/p>\n<\/p>\n<p><p>\u6bcf\u4e2aPython\u5bf9\u8c61\uff08\u6a21\u5757\u3001\u7c7b\u3001\u65b9\u6cd5\u3001\u51fd\u6570\uff09\u90fd\u6709\u4e00\u4e2a<code>__doc__<\/code>\u5c5e\u6027\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u8be5\u5bf9\u8c61\u7684\u6587\u6863\u5b57\u7b26\u4e32\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u67e5\u770b\u6a21\u5757\u7684\u6587\u6863\u5b57\u7b26\u4e32<\/strong><\/p>\n<\/p>\n<p><p>\u76f4\u63a5\u8bbf\u95ee\u6a21\u5757\u7684<code>__doc__<\/code>\u5c5e\u6027\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(os.__doc__)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u67e5\u770b\u51fd\u6570\u6216\u7c7b\u7684\u6587\u6863\u5b57\u7b26\u4e32<\/strong><\/p>\n<\/p>\n<p><p>\u8bbf\u95ee\u7279\u5b9a\u51fd\u6570\u6216\u7c7b\u7684<code>__doc__<\/code>\u5c5e\u6027\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(os.path.join.__doc__)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u5728\u7ebf\u6587\u6863\u548c\u5916\u90e8\u8d44\u6e90<\/p>\n<\/p>\n<p><p>\u9664\u4e86Python\u5185\u7f6e\u7684\u6587\u6863\u67e5\u770b\u529f\u80fd\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u83b7\u53d6\u6587\u6863\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Python\u5b98\u65b9\u6587\u6863<\/strong><\/p>\n<\/p>\n<p><p>Python\u7684\u5b98\u65b9\u7f51\u7ad9\u63d0\u4f9b\u4e86\u8be6\u7ec6\u7684\u6587\u6863\u8d44\u6e90\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95ee <a href=\"https:\/\/docs.python.org\/\">Python\u5b98\u65b9\u6587\u6863<\/a> \u83b7\u53d6\u6700\u65b0\u7684\u6587\u6863\u4fe1\u606f\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7b2c\u4e09\u65b9\u5e93\u7684\u6587\u6863<\/strong><\/p>\n<\/p>\n<p><p>\u5bf9\u4e8e\u7b2c\u4e09\u65b9\u5e93\uff0c\u4f8b\u5982NumPy\u3001Pandas\u7b49\uff0c\u901a\u5e38\u4f1a\u6709\u4e13\u95e8\u7684\u6587\u6863\u7f51\u7ad9\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7Google\u641c\u7d22\u6216\u8bbf\u95ee\u5e93\u7684GitHub\u9875\u9762\u627e\u5230\u76f8\u5173\u94fe\u63a5\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09<\/p>\n<\/p>\n<p><p>\u73b0\u4ee3\u7684\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08\u5982PyCharm\u3001VS Code\u7b49\uff09\u901a\u5e38\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u81ea\u52a8\u8865\u5168\u548c\u6587\u6863\u67e5\u770b\u529f\u80fd\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u81ea\u52a8\u8865\u5168<\/strong><\/p>\n<\/p>\n<p><p>\u5f53\u60a8\u5728IDE\u4e2d\u7f16\u5199\u4ee3\u7801\u65f6\uff0c\u901a\u5e38\u53ef\u4ee5\u901a\u8fc7\u8f93\u5165\u90e8\u5206\u51fd\u6570\u6216\u65b9\u6cd5\u540d\u79f0\uff0c\u8c03\u7528IDE\u7684\u81ea\u52a8\u8865\u5168\u529f\u80fd\uff0c\u67e5\u770b\u76f8\u5173\u6587\u6863\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5185\u7f6e\u6587\u6863\u67e5\u770b<\/strong><\/p>\n<\/p>\n<p><p>\u5728PyCharm\u7b49IDE\u4e2d\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u60ac\u505c\u5728\u67d0\u4e2a\u51fd\u6570\u3001\u7c7b\u4e0a\uff0c\u6216\u8005\u4f7f\u7528\u5feb\u6377\u952e\uff08\u5982Ctrl+Q\uff09\u6765\u67e5\u770b\u8be6\u7ec6\u7684\u6587\u6863\u4fe1\u606f\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u603b\u7ed3\u6765\u8bf4\uff0cPython\u63d0\u4f9b\u4e86\u591a\u79cd\u67e5\u770b\u6587\u6863\u7684\u65b9\u5f0f\uff0c\u4ece\u5185\u7f6e\u7684<code>help()<\/code>\u548c<code>dir()<\/code>\u51fd\u6570\uff0c\u5230\u5728\u7ebf\u6587\u6863\u548cIDE\u5de5\u5177\uff0c\u60a8\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u3002\u901a\u8fc7\u8fd9\u4e9b\u65b9\u5f0f\uff0c\u60a8\u53ef\u4ee5\u66f4\u597d\u5730\u7406\u89e3\u548c\u4f7f\u7528Python\u7684\u5404\u79cd\u529f\u80fd\u548c\u6a21\u5757\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u67e5\u770b\u6587\u6863\u5185\u5bb9\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e0d\u540c\u7684\u5e93\u6765\u8bfb\u53d6\u548c\u67e5\u770b\u6587\u6863\u5185\u5bb9\u3002\u4f8b\u5982\uff0c\u5bf9\u4e8e\u6587\u672c\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684<code>open()<\/code>\u51fd\u6570\u6765\u6253\u5f00\u6587\u4ef6\u5e76\u8bfb\u53d6\u5185\u5bb9\u3002\u5bf9\u4e8e\u66f4\u590d\u6742\u7684\u6587\u4ef6\u683c\u5f0f\uff0c\u5982PDF\u6216Word\u6587\u6863\uff0c\u53ef\u4ee5\u4f7f\u7528<code>PyPDF2<\/code>\u6216<code>python-docx<\/code>\u7b49\u5e93\u3002\u8fd9\u6837\uff0c\u7528\u6237\u53ef\u4ee5\u8f7b\u677e\u83b7\u53d6\u6587\u6863\u7684\u5177\u4f53\u5185\u5bb9\u3002<\/p>\n<p><strong>Python\u4e2d\u6709\u54ea\u4e9b\u5e93\u53ef\u4ee5\u7528\u6765\u8bfb\u53d6\u4e0d\u540c\u7c7b\u578b\u7684\u6587\u6863\uff1f<\/strong><br \/>Python\u63d0\u4f9b\u4e86\u591a\u79cd\u5e93\u6765\u5904\u7406\u4e0d\u540c\u7c7b\u578b\u7684\u6587\u6863\u3002\u4f8b\u5982\uff0c<code>pandas<\/code>\u53ef\u4ee5\u7528\u4e8e\u8bfb\u53d6Excel\u6587\u4ef6\uff0c<code>PyPDF2<\/code>\u9002\u7528\u4e8ePDF\u6587\u4ef6\uff0c<code>python-docx<\/code>\u7528\u4e8eWord\u6587\u6863\uff0c\u800c<code>csv<\/code>\u6a21\u5757\u5219\u53ef\u4ee5\u5904\u7406CSV\u6587\u4ef6\u3002\u8fd9\u4e9b\u5e93\u5404\u5177\u7279\u8272\uff0c\u80fd\u591f\u6ee1\u8db3\u4e0d\u540c\u6587\u6863\u683c\u5f0f\u7684\u8bfb\u53d6\u9700\u6c42\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u8bfb\u53d6\u6587\u6863\u65f6\u51fa\u73b0\u7684\u9519\u8bef\uff1f<\/strong><br \/>\u5728\u8bfb\u53d6\u6587\u6863\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u6587\u4ef6\u4e0d\u5b58\u5728\u3001\u683c\u5f0f\u9519\u8bef\u6216\u6743\u9650\u4e0d\u8db3\u7b49\u95ee\u9898\u3002\u4e3a\u4e86\u786e\u4fdd\u7a0b\u5e8f\u7684\u5065\u58ee\u6027\uff0c\u53ef\u4ee5\u4f7f\u7528\u5f02\u5e38\u5904\u7406\u673a\u5236\uff0c\u4f8b\u5982<code>try...except<\/code>\u7ed3\u6784\uff0c\u6765\u6355\u83b7\u8fd9\u4e9b\u9519\u8bef\u5e76\u8f93\u51fa\u76f8\u5e94\u7684\u63d0\u793a\u4fe1\u606f\u3002\u8fd9\u5c06\u4f7f\u7528\u6237\u5728\u64cd\u4f5c\u6587\u6863\u65f6\u66f4\u52a0\u987a\u7545\uff0c\u5e76\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u56f0\u6270\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u67e5\u770b\u6587\u6863\u5185\u5bb9\u7684\u5e38\u7528\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528help()\u51fd\u6570\u3001dir()\u51fd\u6570\u3001\u67e5\u770b\u6a21\u5757\u7684__doc__\u5c5e\u6027\u3001 [&hellip;]","protected":false},"author":3,"featured_media":1006585,"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\/1006577"}],"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=1006577"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1006577\/revisions"}],"predecessor-version":[{"id":1006588,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1006577\/revisions\/1006588"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1006585"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1006577"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1006577"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1006577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}