{"id":3488,"date":"2025-06-03T14:36:46","date_gmt":"2025-06-04T07:35:45","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=3488"},"modified":"2025-06-04T14:36:46","modified_gmt":"2025-06-04T07:35:45","slug":"%e4%ba%86%e8%a7%a3python%e4%b8%ad%e7%9a%84members%e5%87%bd%e6%95%b8%e5%8a%9f%e8%83%bd","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/python\/%e4%ba%86%e8%a7%a3python%e4%b8%ad%e7%9a%84members%e5%87%bd%e6%95%b8%e5%8a%9f%e8%83%bd\/","title":{"rendered":"\u6df1\u5165\u63a2\u7d22 Python \u4e2d\u7684 `members()` \u51fd\u6578\uff1a\u7528\u6cd5\u8207\u6700\u4f73\u5be6\u8e10\uff082025 \u6700\u65b0\u6559\u5b78\uff09"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Python, members(), Python \u65b9\u6cd5\u6559\u5b78, Python \u5c6c\u6027\"><\/p>\n<h1>\u6df1\u5165\u63a2\u7d22 Python \u4e2d\u7684 <code>members()<\/code> \u51fd\u6578\uff1a\u7528\u6cd5\u8207\u6700\u4f73\u5be6\u8e10\uff082025 \u6700\u65b0\u6559\u5b78\uff09<\/h1>\n<p>\u5728 Python \u4e2d\uff0c`members()` \u51fd\u6578\u4e26\u4e0d\u662f\u5167\u5efa\u7684\u6a19\u6e96\u51fd\u6578\uff0c\u800c\u662f\u901a\u5e38\u8207\u7269\u4ef6\u7684\u5c6c\u6027\u76f8\u95dc\u7684\u529f\u80fd\u3002\u9019\u7bc7\u6587\u7ae0\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528 Python \u7684 `dir()` \u548c `__dict__` \u65b9\u6cd5\u4f86\u9054\u5230\u985e\u4f3c\u65bc `members()` \u7684\u6548\u679c\uff0c\u4e26\u63d0\u4f9b\u4e86\u5b8c\u6574\u7684\u6559\u5b78\u6d41\u7a0b\u3002<\/p>\n<h2>\u4ec0\u9ebc\u662f <code>members()<\/code> \u51fd\u6578\uff1f<\/h2>\n<p>\u96d6\u7136 Python \u4e26\u6c92\u6709\u5c08\u9580\u7684 `members()` \u65b9\u6cd5\uff0c\u4f46\u6211\u5011\u53ef\u4ee5\u900f\u904e `dir()` \u548c `__dict__` \u65b9\u6cd5\u4f86\u7372\u53d6\u7269\u4ef6\u7684\u5c6c\u6027\u5217\u8868\u3002\u9019\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u5e6b\u52a9\u6211\u5011\u7372\u5f97\u7269\u4ef6\u7684\u6240\u6709\u5c6c\u6027\uff0c\u5305\u62ec\u65b9\u6cd5\u548c\u5c6c\u6027\u3002<\/p>\n<h2>\u4f7f\u7528 <code>dir()<\/code> \u65b9\u6cd5<\/h2>\n<p>`dir()` \u65b9\u6cd5\u53ef\u4ee5\u8fd4\u56de\u4e00\u500b\u5305\u542b\u7269\u4ef6\u5c6c\u6027\u7684\u5217\u8868\u3002\u9019\u662f\u4e00\u500b\u7c21\u55ae\u7684\u7bc4\u4f8b\uff1a<\/p>\n<pre class=\"brush: python\">\nclass MyClass:\n    def __init__(self):\n        self.a = 1\n        self.b = 2\n\nobj = MyClass()\n\n# \u53d6\u5f97\u7269\u4ef6\u7684\u5c6c\u6027\u5217\u8868\nprint(dir(obj))\n<\/pre>\n<p>\u9019\u6bb5\u7a0b\u5f0f\u78bc\u5c07\u6703\u8f38\u51fa\u985e\u4f3c\u65bc\u4ee5\u4e0b\u7684\u5167\u5bb9\uff1a<\/p>\n<pre class=\"brush: python\">\n['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'a', 'b']\n<\/pre>\n<h2>\u4f7f\u7528 <code>__dict__<\/code> \u65b9\u6cd5<\/h2>\n<p>`__dict__` \u662f\u4e00\u500b\u5c6c\u6027\uff0c\u8fd4\u56de\u7269\u4ef6\u7684\u5c6c\u6027\u5b57\u5178\uff0c\u9019\u662f\u53e6\u4e00\u7a2e\u7372\u53d6\u7269\u4ef6\u5c6c\u6027\u7684\u65b9\u6cd5\uff1a<\/p>\n<pre class=\"brush: python\">\n# \u53d6\u5f97\u7269\u4ef6\u7684\u5c6c\u6027\u5b57\u5178\nprint(obj.__dict__)\n<\/pre>\n<p>\u9019\u6bb5\u7a0b\u5f0f\u78bc\u7684\u8f38\u51fa\u5c07\u6703\u662f\uff1a<\/p>\n<pre class=\"brush: python\">\n{'a': 1, 'b': 2}\n<\/pre>\n<h2>\u932f\u8aa4\u6392\u9664<\/h2>\n<p>\u5982\u679c\u4f60\u4f7f\u7528 `members()` \u65b9\u6cd5\u4e14\u51fa\u73fe\u932f\u8aa4\uff0c\u8acb\u6aa2\u67e5\u4f60\u662f\u5426\u610f\u5716\u4f7f\u7528 `dir()` \u6216 `__dict__` \u65b9\u6cd5\uff0c\u56e0\u70ba `members()` \u672c\u8eab\u5728 Python \u4e2d\u662f\u4e0d\u5b58\u5728\u7684\u3002\u78ba\u4fdd\u4f7f\u7528\u6b63\u78ba\u7684\u8a9e\u6cd5\u4f86\u7372\u53d6\u7269\u4ef6\u7684\u5c6c\u6027\u3002<\/p>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u9664\u4e86\u4e0a\u8ff0\u65b9\u6cd5\uff0c\u4e86\u89e3\u7269\u4ef6\u7684\u5c6c\u6027\u548c\u65b9\u6cd5\u5c0d\u65bc\u958b\u767c\u8907\u96dc\u7684 Python \u61c9\u7528\u7a0b\u5e8f\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u4f60\u53ef\u4ee5\u9032\u4e00\u6b65\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528\u9019\u4e9b\u5c6c\u6027\u4f86\u5275\u5efa\u66f4\u9ad8\u6548\u7684\u7a0b\u5f0f\u78bc\uff0c\u4f8b\u5982\u900f\u904e\u53cd\u5c04\u4f86\u52d5\u614b\u8abf\u7528\u65b9\u6cd5\uff0c\u6216\u4f7f\u7528\u88dd\u98fe\u5668\u4f86\u589e\u5f37\u529f\u80fd\u3002<\/p>\n<h2>\u7d50\u8ad6<\/h2>\n<p>\u5728 Python \u4e2d\uff0c\u96d6\u7136\u6c92\u6709\u5167\u5efa\u7684 `members()` \u65b9\u6cd5\uff0c\u4f46\u53ef\u4ee5\u4f7f\u7528 `dir()` \u548c `__dict__` \u4f86\u9054\u5230\u76f8\u4f3c\u7684\u6548\u679c\u3002\u9019\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u6e05\u695a\u4e86\u89e3\u7269\u4ef6\u7684\u7d50\u69cb\uff0c\u4e26\u9032\u4e00\u6b65\u63d0\u5347\u7a0b\u5f0f\u8a2d\u8a08\u7684\u6548\u7387\u3002<\/p>\n<p>\u5c0d\u65bc\u9032\u4e00\u6b65\u7684 Python \u5b78\u7fd2\uff0c\u4f60\u53ef\u4ee5\u53c3\u8003\u9019\u7bc7 [Python \u6559\u5b78\u6587\u737b](https:\/\/vocus.cc)\uff0c\u9019\u5c07\u5c0d\u4f60\u7684\u5b78\u7fd2\u4e4b\u8def\u6709\u6240\u5e6b\u52a9\u3002<\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<p>**\u554f\uff1a`dir()` \u548c `__dict__` \u6709\u4ec0\u9ebc\u4e0d\u540c\u4e4b\u8655\uff1f**<br \/>\n\u7b54\uff1a`dir()` \u8fd4\u56de\u4e00\u500b\u5305\u542b\u7269\u4ef6\u6240\u6709\u5c6c\u6027\u548c\u65b9\u6cd5\u7684\u5217\u8868\uff0c\u800c `__dict__` \u8fd4\u56de\u4e00\u500b\u5b57\u5178\uff0c\u50c5\u5305\u542b\u7269\u4ef6\u7684\u5be6\u4f8b\u5c6c\u6027\u3002<\/p>\n<p>**\u554f\uff1a\u6211\u53ef\u4ee5\u5728\u51fd\u6578\u4e2d\u4f7f\u7528 `members()` \u55ce\uff1f**<br \/>\n\u7b54\uff1a\u7531\u65bc `members()` \u5728 Python \u4e2d\u4e26\u4e0d\u5b58\u5728\uff0c\u4f60\u61c9\u8a72\u4f7f\u7528 `dir()` \u6216 `__dict__` \u4f86\u7372\u53d6\u7269\u4ef6\u7684\u5c6c\u6027\u3002<\/p>\n<p>**\u554f\uff1a\u5982\u4f55\u7372\u53d6\u6240\u6709\u985e\u5225\u7684\u5c6c\u6027\uff1f**<br \/>\n\u7b54\uff1a\u53ef\u4ee5\u4f7f\u7528 `vars()` \u51fd\u6578\uff0c\u9019\u5c07\u8fd4\u56de\u6307\u5b9a\u5c0d\u8c61\u7684 `__dict__`\uff0c\u8a72\u5b57\u5178\u5305\u542b\u6240\u6709\u5c6c\u6027\u53ca\u5176\u5c0d\u61c9\u7684\u503c\u3002<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3Python\u4e2d\u7684members()\u51fd\u6578\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u6aa2\u67e5\u7269\u4ef6\u7684\u5c6c\u6027\u548c\u65b9\u6cd5\uff0c\u4e26\u63d0\u4f9b\u4e00\u500b\u53ef\u4ee5\u67e5\u770b\u7269\u4ef6\u7684\u5c6c\u6027\u548c\u65b9\u6cd5\u7684\u7c21\u55ae\u65b9\u6cd5\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-3488","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-Ug","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3488","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=3488"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3488\/revisions"}],"predecessor-version":[{"id":3489,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3488\/revisions\/3489"}],"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=3488"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=3488"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=3488"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}