{"id":3110,"date":"2025-05-28T16:18:45","date_gmt":"2025-06-04T08:53:45","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=3110"},"modified":"2025-06-04T16:18:45","modified_gmt":"2025-06-04T08:53:45","slug":"%e4%ba%86%e8%a7%a3python%e7%9a%84dir%e5%87%bd%e6%95%b8-2","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/python\/%e4%ba%86%e8%a7%a3python%e7%9a%84dir%e5%87%bd%e6%95%b8-2\/","title":{"rendered":"\u6df1\u5165\u4e86\u89e3 Python \u7684 dir() \u51fd\u6578\uff1a\u4f7f\u7528\u6280\u5de7\u8207\u6700\u4f73\u5be6\u8e10\uff082025 \u66f4\u65b0\uff09"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Python, dir()\"><\/p>\n<h1>\u6df1\u5165\u4e86\u89e3 Python \u7684 dir() \u51fd\u6578\uff1a\u4f7f\u7528\u6280\u5de7\u8207\u6700\u4f73\u5be6\u8e10\uff082025 \u66f4\u65b0\uff09<\/h1>\n<p>\u5728 Python \u7a0b\u5f0f\u958b\u767c\u904e\u7a0b\u4e2d\uff0c`dir()` \u51fd\u6578\u662f\u4e00\u500b\u6975\u70ba\u6709\u7528\u7684\u5de5\u5177\u3002\u5b83\u4e0d\u50c5\u80fd\u8b93\u958b\u767c\u8005\u65b9\u4fbf\u5730\u67e5\u770b\u7269\u4ef6\u7684\u5c6c\u6027\u548c\u65b9\u6cd5\uff0c\u9084\u80fd\u5e6b\u52a9\u7406\u89e3\u6a21\u7d44\u4e2d\u5b9a\u7fa9\u7684\u5404\u7a2e\u540d\u7a31\u3002\u672c\u6587\u5c07\u5168\u9762\u4ecb\u7d39 `dir()` \u51fd\u6578\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u5305\u62ec\u57fa\u672c\u8207\u9032\u968e\u7528\u6cd5\uff0c\u4e26\u63d0\u4f9b\u5be6\u4f5c\u7bc4\u4f8b\u3001\u932f\u8aa4\u6392\u9664\u6280\u5de7\u53ca\u5ef6\u4f38\u61c9\u7528\u3002<\/p>\n<h2>\u4ec0\u9ebc\u662f dir() \u51fd\u6578\uff1f<\/h2>\n<p>`dir()` \u51fd\u6578\u662f Python \u4e2d\u7684\u5167\u5efa\u51fd\u6578\uff0c\u4e3b\u8981\u7528\u65bc\u67e5\u770b\u7269\u4ef6\u7684\u5c6c\u6027\u548c\u65b9\u6cd5\uff0c\u5b83\u80fd\u5920\u5217\u51fa\u7269\u4ef6\u6216\u6a21\u7d44\u4e2d\u53ef\u7528\u7684\u540d\u7a31\u3002\u9019\u5c0d\u65bc\u8abf\u8a66\u548c\u7406\u89e3\u4ee3\u78bc\u7d50\u69cb\u90fd\u975e\u5e38\u91cd\u8981\u3002<\/p>\n<h2>\u5982\u4f55\u4f7f\u7528 dir() \u51fd\u6578\uff1f<\/h2>\n<p>\u4f7f\u7528 `dir()` \u51fd\u6578\u975e\u5e38\u7c21\u55ae\u3002\u53ea\u9700\u5728\u7d42\u7aef\u6a5f\u4e2d\u8f38\u5165 `dir()`\uff0c\u4e26\u50b3\u5165\u60f3\u8981\u67e5\u770b\u7684\u7269\u4ef6\u6216\u6a21\u7d44\uff0c\u5373\u53ef\u7372\u5f97\u8a72\u7269\u4ef6\u6216\u6a21\u7d44\u7684\u6240\u6709\u5c6c\u6027\u548c\u65b9\u6cd5\u3002<\/p>\n<p>&#8220;`python<br \/>\n# \u67e5\u770b\u5b57\u4e32\u7269\u4ef6\u7684\u5c6c\u6027\u548c\u65b9\u6cd5<br \/>\nprint(dir(str))<\/p>\n<p># \u67e5\u770b math \u6a21\u7d44\u7684\u5c6c\u6027\u548c\u65b9\u6cd5<br \/>\nimport math<br \/>\nprint(dir(math))<br \/>\n&#8220;`<\/p>\n<h2>dir() \u51fd\u6578\u7684\u57fa\u672c\u7528\u6cd5<\/h2>\n<p>\u4ee5\u4e0b\u662f `dir()` \u51fd\u6578\u7684\u57fa\u672c\u7528\u6cd5\uff0c\u900f\u904e\u50b3\u5165\u4e00\u500b\u7269\u4ef6\u6216\u6a21\u7d44\uff0c\u53ef\u4ee5\u8f15\u9b06\u7372\u5f97\u5176\u5c6c\u6027\u548c\u65b9\u6cd5\u5217\u8868\u3002<\/p>\n<p>&#8220;`python<br \/>\n# \u67e5\u770b\u5b57\u4e32\u7269\u4ef6\u7684\u5c6c\u6027\u548c\u65b9\u6cd5<br \/>\nprint(dir(str))<\/p>\n<p># \u67e5\u770b math \u6a21\u7d44\u7684\u5c6c\u6027\u548c\u65b9\u6cd5<br \/>\nimport math<br \/>\nprint(dir(math))<br \/>\n&#8220;`<\/p>\n<h2>dir() \u51fd\u6578\u7684\u9ad8\u7d1a\u7528\u6cd5<\/h2>\n<p>`dir()` \u51fd\u6578\u9084\u53ef\u4ee5\u7528\u65bc\u67e5\u770b\u7279\u5b9a\u5c6c\u6027\u548c\u65b9\u6cd5\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u9ad8\u7d1a\u7528\u6cd5\u7684\u7bc4\u4f8b\uff1a<\/p>\n<p>&#8220;`python<br \/>\n# \u67e5\u770b\u5b57\u4e32\u7269\u4ef6\u7684\u7279\u5b9a\u5c6c\u6027\u548c\u65b9\u6cd5<br \/>\nprint(dir(str).count(&#8216;split&#8217;))  # \u8a08\u7b97 &#8216;split&#8217; \u65b9\u6cd5\u7684\u6578\u91cf<\/p>\n<p># \u67e5\u770b math \u6a21\u7d44\u4e2d\u5b9a\u7fa9\u7684\u540d\u7a31<br \/>\nimport math<br \/>\nprint(dir(math).count(&#8216;__name__&#8217;))  # \u8a08\u7b97 &#8216;__name__&#8217; \u7684\u6578\u91cf<br \/>\n&#8220;`<\/p>\n<h2>\u932f\u8aa4\u6392\u9664\u6280\u5de7<\/h2>\n<p>\u5728\u4f7f\u7528 `dir()` \u51fd\u6578\u6642\uff0c\u82e5\u767c\u73fe\u6c92\u6709\u8fd4\u56de\u9810\u671f\u7684\u5c6c\u6027\u6216\u65b9\u6cd5\uff0c\u8acb\u6aa2\u67e5\u4ee5\u4e0b\u5e7e\u9ede\uff1a<\/p>\n<p>1. \u78ba\u8a8d\u7269\u4ef6\u6216\u6a21\u7d44\u662f\u5426\u6b63\u78ba\u5c0e\u5165\u3002<br \/>\n2. \u6aa2\u67e5\u7269\u4ef6\u7684\u985e\u578b\u662f\u5426\u6b63\u78ba\u3002<br \/>\n3. \u78ba\u8a8d Python \u7248\u672c\u662f\u5426\u652f\u6301\u8a72\u5c6c\u6027\u6216\u65b9\u6cd5\u3002<\/p>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>`dir()` \u51fd\u6578\u53ef\u4ee5\u8207\u5176\u4ed6\u5167\u5efa\u51fd\u6578\u5982 `help()` \u7d50\u5408\u4f7f\u7528\uff0c\u4ee5\u7372\u53d6\u66f4\u8a73\u7d30\u7684\u4f7f\u7528\u8aaa\u660e\u548c\u7bc4\u4f8b\uff1a<\/p>\n<p>&#8220;`python<br \/>\n# \u7372\u53d6\u5b57\u4e32\u7269\u4ef6\u7684\u8aaa\u660e<br \/>\nhelp(str)<br \/>\n&#8220;`<\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86 Python \u4e2d\u7684 `dir()` \u51fd\u6578\uff0c\u91cd\u9ede\u5728\u65bc\u5982\u4f55\u67e5\u770b\u7269\u4ef6\u7684\u5c6c\u6027\u548c\u65b9\u6cd5\uff0c\u4e26\u63a2\u8a0e\u4e86\u5176\u9ad8\u7d1a\u7528\u6cd5\u3002`dir()` \u51fd\u6578\u662f\u7406\u89e3 Python \u4e2d\u7269\u4ef6\u548c\u6a21\u7d44\u7684\u91cd\u8981\u5de5\u5177\uff0c\u5c0d\u65bc\u63d0\u5347\u958b\u767c\u8005\u7684\u6548\u7387\u6709\u8457\u4e0d\u53ef\u5ffd\u8996\u7684\u4f5c\u7528\u3002\u5982\u9700\u66f4\u6df1\u5165\u7684 Python \u6559\u5b78\uff0c\u5efa\u8b70\u53c3\u8003\u76f8\u95dc\u8cc7\u6e90\uff0c\u4f8b\u5982 [vocus.cc \u7684 Python \u6559\u5b78](https:\/\/vocus.cc)\u3002<\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<p>**Q1: dir() \u51fd\u6578\u662f\u5426\u53ea\u80fd\u7528\u65bc\u5167\u5efa\u985e\u578b\uff1f**<br \/>\nA1: \u4e0d\uff0c`dir()` \u51fd\u6578\u53ef\u4ee5\u7528\u65bc\u4efb\u4f55\u7269\u4ef6\uff0c\u5305\u62ec\u81ea\u5b9a\u7fa9\u985e\u5225\u548c\u7b2c\u4e09\u65b9\u6a21\u7d44\u3002<\/p>\n<p>**Q2: \u5982\u4f55\u7372\u5f97\u7269\u4ef6\u7684\u7279\u5b9a\u65b9\u6cd5\u7684\u8aaa\u660e\uff1f**<br \/>\nA2: \u60a8\u53ef\u4ee5\u4f7f\u7528 `help()` \u51fd\u6578\uff0c\u4f8b\u5982 `help(str.split)` \u4f86\u7372\u5f97\u7279\u5b9a\u65b9\u6cd5\u7684\u8a73\u7d30\u8aaa\u660e\u3002<\/p>\n<p>**Q3: \u4f7f\u7528 dir() \u51fd\u6578\u6642\uff0c\u70ba\u4ec0\u9ebc\u6709\u6642\u5019\u770b\u4e0d\u5230\u67d0\u4e9b\u5c6c\u6027\u6216\u65b9\u6cd5\uff1f**<br \/>\nA3: \u9019\u53ef\u80fd\u662f\u56e0\u70ba\u8a72\u5c6c\u6027\u6216\u65b9\u6cd5\u662f\u79c1\u6709\u7684\uff08\u4ee5\u96d9\u4e0b\u5283\u7dda\u958b\u982d\uff09\uff0c\u6216\u8005\u662f\u56e0\u70ba\u8a72\u7269\u4ef6\u6c92\u6709\u5b9a\u7fa9\u76f8\u61c9\u7684\u5c6c\u6027\u6216\u65b9\u6cd5\u3002<\/p>\n<p>&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>dir()\u51fd\u6578\u662fPython\u4e2d\u7684\u4e00\u500b\u91cd\u8981\u51fd\u6578\uff0c\u53ef\u4ee5\u7528\u4f86\u67e5\u770b\u7269\u4ef6\u7684\u5c6c\u6027\u548c\u65b9\u6cd5\uff0c\u672c\u6587\u5c07\u4ecb\u7d39dir()\u51fd\u6578\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u4ee5\u53ca\u5982\u4f55\u5229\u7528\u5b83\u4f86\u63d0\u9ad8\u7a0b\u5f0f\u7684\u6548\u7387\u3002<\/p>\n","protected":false},"author":1,"featured_media":2518,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[18],"tags":[15],"class_list":["post-3110","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-python"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2022\/12\/DALL\u00b7E-2022-12-28-14.25.55-\u62f7\u8c9d2.png","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-Oa","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3110","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=3110"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3110\/revisions"}],"predecessor-version":[{"id":3111,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3110\/revisions\/3111"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/2518"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=3110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=3110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=3110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}