{"id":3615,"date":"2025-06-02T14:37:00","date_gmt":"2025-06-04T07:36:00","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=3615"},"modified":"2025-06-04T14:37:00","modified_gmt":"2025-06-04T07:36:00","slug":"%e4%ba%86%e8%a7%a3python%e4%b8%ad%e7%9a%84notimplementederror%e7%9a%84%e5%8a%9f%e8%83%bd%e8%88%87%e4%bd%bf%e7%94%a8%e6%96%b9%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/python\/%e4%ba%86%e8%a7%a3python%e4%b8%ad%e7%9a%84notimplementederror%e7%9a%84%e5%8a%9f%e8%83%bd%e8%88%87%e4%bd%bf%e7%94%a8%e6%96%b9%e5%bc%8f\/","title":{"rendered":"\u6df1\u5165\u4e86\u89e3Python\u4e2d\u7684NotImplementedError\uff1a\u529f\u80fd\u3001\u4f7f\u7528\u65b9\u5f0f\u8207\u6700\u4f73\u5be6\u8e10"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Python, NotImplementedError, \u7a0b\u5f0f\u8a2d\u8a08, \u62bd\u8c61\u985e, \u932f\u8aa4\u8655\u7406\"><\/p>\n<h1>\u4ec0\u9ebc\u662fPython\u7684NotImplementedError\uff1f<\/h1>\n<p>\u5728Python\u4e2d\uff0cNotImplementedError\u662f\u4e00\u500b\u7279\u6b8a\u7684\u4f8b\u5916\u985e\u578b\uff0c\u4e3b\u8981\u7528\u4f86\u6307\u793a\u67d0\u500b\u529f\u80fd\u5c1a\u672a\u5be6\u73fe\u3002\u9019\u500b\u5167\u7f6e\u7684\u4f8b\u5916\u5c0d\u65bc\u958b\u767c\u8005\u4f86\u8aaa\u975e\u5e38\u91cd\u8981\uff0c\u56e0\u70ba\u5b83\u53ef\u4ee5\u63d0\u9192\u6211\u5011\u5728\u8a2d\u8a08\u7a0b\u5e8f\u6642\uff0c\u67d0\u4e9b\u529f\u80fd\u9084\u9700\u8981\u9032\u4e00\u6b65\u7684\u5be6\u73fe\u3002<\/p>\n<h2>NotImplementedError\u7684\u4f7f\u7528<\/h2>\n<p>NotImplementedError\u5e38\u7528\u65bc\u62bd\u8c61\u985e\u4e2d\u7684\u7279\u5b9a\u60c5\u6cc1\u3002\u62bd\u8c61\u985e\u662f\u4e00\u7a2e\u7279\u6b8a\u7684\u985e\u578b\uff0c\u5b83\u5b9a\u7fa9\u4e86\u4e00\u7d44\u63a5\u53e3\uff0c\u4f46\u4e0d\u63d0\u4f9b\u5177\u9ad4\u7684\u5be6\u73fe\u3002\u9019\u8981\u6c42\u5176\u5b50\u985e\u5fc5\u9808\u5be6\u73fe\u9019\u4e9b\u63a5\u53e3\uff0c\u5426\u5247\u5c07\u6703\u62cb\u51faNotImplementedError\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u7bc4\uff1a\u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b\u62bd\u8c61\u985eFoo\uff0c\u5b83\u5305\u542b\u4e00\u500b\u62bd\u8c61\u65b9\u6cd5bar\uff1a<\/p>\n<p>&#8220;`python<br \/>\nclass Foo:<br \/>\n    def bar(self):<br \/>\n        raise NotImplementedError(&#8220;Subclasses must implement this method&#8221;)<br \/>\n&#8220;`<\/p>\n<p>\u82e5\u6211\u5011\u5275\u5efa\u4e00\u500bFoo\u7684\u5b50\u985e\uff0c\u4f46\u672a\u5be6\u73febar\u65b9\u6cd5\uff0c\u5728\u57f7\u884c\u6642\u6703\u62cb\u51faNotImplementedError\uff1a<\/p>\n<p>&#8220;`python<br \/>\nclass MyFoo(Foo):<br \/>\n    pass<\/p>\n<p>my_foo = MyFoo()<br \/>\nmy_foo.bar()  # \u9019\u88e1\u5c07\u62cb\u51faNotImplementedError<br \/>\n&#8220;`<\/p>\n<p>\u57f7\u884c\u4ee5\u4e0a\u4ee3\u78bc\uff0c\u60a8\u5c07\u770b\u5230\u5982\u4e0b\u932f\u8aa4\u4fe1\u606f\uff1a<\/p>\n<p>&#8220;`<br \/>\nNotImplementedError: Subclasses must implement this method<br \/>\n&#8220;`<\/p>\n<p>\u6b64\u5916\uff0cNotImplementedError\u4e5f\u53ef\u4ee5\u7528\u4f86\u6a19\u8a18\u67d0\u500b\u9810\u671f\u7684\u529f\u80fd\uff0c\u96d6\u7136\u76ee\u524d\u5c1a\u672a\u5be6\u73fe\u3002\u6bd4\u5982\u8aaa\uff0c\u6211\u5011\u6709\u4e00\u500b\u7528\u65bc\u8a08\u7b97\u5169\u500b\u6578\u5b57\u548c\u7684\u51fd\u6578\uff1a<\/p>\n<p>&#8220;`python<br \/>\ndef add(x, y):<br \/>\n    return x + y<br \/>\n&#8220;`<\/p>\n<p>\u5982\u679c\u6211\u5011\u8a08\u5283\u8981\u6dfb\u52a0\u4e00\u500b\u8a08\u7b97\u5169\u500b\u6578\u5b57\u5dee\u7684\u529f\u80fd\uff0c\u4f46\u5c1a\u672a\u5be6\u73fe\uff0c\u6211\u5011\u53ef\u4ee5\u62cb\u51faNotImplementedError\u4f86\u63d0\u793a\u672a\u4f86\u7684\u5be6\u4f5c\uff1a<\/p>\n<p>&#8220;`python<br \/>\ndef subtract(x, y):<br \/>\n    raise NotImplementedError(&#8220;This method will be implemented in future versions&#8221;)<br \/>\n&#8220;`<\/p>\n<p>\u57f7\u884c\u6b64\u4ee3\u78bc\u6642\uff0c\u5c07\u5f15\u767c\u5982\u4e0b\u932f\u8aa4\uff1a<\/p>\n<p>&#8220;`<br \/>\nNotImplementedError: This method will be implemented in future versions<br \/>\n&#8220;`<\/p>\n<h2>NotImplementedError\u7684\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u4f7f\u7528NotImplementedError\u6642\uff0c\u958b\u767c\u8005\u61c9\u8a72\u6ce8\u610f\uff0c\u9019\u500b\u4f8b\u5916\u4e0d\u61c9\u8a72\u7528\u65bc\u6a19\u8b58\u67d0\u4e9b\u529f\u80fd\u6c38\u9060\u4e0d\u6703\u5be6\u73fe\u3002\u9019\u53ef\u80fd\u6703\u5c0e\u81f4\u5176\u4ed6\u958b\u767c\u8005\u8a8d\u70ba\u9019\u9805\u529f\u80fd\u5728\u672a\u4f86\u53ef\u80fd\u6703\u5be6\u73fe\uff0c\u9032\u800c\u9020\u6210\u6df7\u6dc6\u3002\u56e0\u6b64\uff0c\u6e05\u6670\u5730\u8a18\u9304\u9019\u4e9b\u60c5\u6cc1\u975e\u5e38\u91cd\u8981\u3002<\/p>\n<h2>\u932f\u8aa4\u6392\u9664\u8207\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u5982\u679c\u60a8\u5728\u4f7f\u7528\u4e2d\u9047\u5230NotImplementedError\uff0c\u8acb\u6aa2\u67e5\u4ee5\u4e0b\u5e7e\u9ede\uff1a<\/p>\n<p>1. **\u78ba\u4fdd\u5b50\u985e\u5be6\u73fe\u4e86\u6240\u6709\u62bd\u8c61\u65b9\u6cd5**\uff1a\u6aa2\u67e5\u662f\u5426\u6240\u6709\u57fa\u65bc\u62bd\u8c61\u985e\u7684\u5b50\u985e\u90fd\u5be6\u73fe\u4e86\u5fc5\u8981\u7684\u65b9\u6cd5\u3002<br \/>\n2. **\u6aa2\u67e5\u662f\u5426\u6709\u907a\u6f0f\u7684\u908f\u8f2f**\uff1a\u5982\u679c\u60a8\u8a2d\u8a08\u4e86\u4e00\u500b\u529f\u80fd\uff0c\u4f46\u5728\u8abf\u7528\u6642\u537b\u62cb\u51faNotImplementedError\uff0c\u8acb\u6aa2\u67e5\u8a72\u529f\u80fd\u7684\u5be6\u73fe\u72c0\u614b\u3002<\/p>\n<p>\u6b64\u5916\uff0cNotImplementedError\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u9010\u6b65\u5be6\u73fe\u5927\u578b\u9805\u76ee\uff0c\u6bd4\u5982\u5728\u9032\u884c\u529f\u80fd\u62c6\u5206\u6642\u4f7f\u7528\uff0c\u9019\u6a23\u53ef\u4ee5\u6e05\u6670\u5730\u6a19\u8a18\u54ea\u4e9b\u529f\u80fd\u5c1a\u5f85\u5be6\u73fe\u3002<\/p>\n<p>\u60a8\u53ef\u4ee5\u53c3\u8003\u9019\u7bc7\u6709\u95dc [Python \u62bd\u8c61\u985e\u7684\u8a73\u7d30\u6559\u5b78](https:\/\/vocus.cc) \u4f86\u6df1\u5165\u4e86\u89e3\u76f8\u95dc\u6982\u5ff5\u3002<\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>Python\u7684NotImplementedError\u662f\u4e00\u500b\u91cd\u8981\u7684\u4f8b\u5916\uff0c\u9069\u5408\u7528\u65bc\u62bd\u8c61\u985e\u548c\u6a19\u8a18\u5c1a\u672a\u5be6\u73fe\u7684\u529f\u80fd\u3002\u6b63\u78ba\u7684\u4f7f\u7528\u65b9\u5f0f\u80fd\u5920\u63d0\u5347\u4ee3\u78bc\u7684\u53ef\u7dad\u8b77\u6027\uff0c\u4e26\u4fc3\u9032\u5718\u968a\u9593\u7684\u6709\u6548\u6e9d\u901a\u3002<\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<p>**Q1: NotImplementedError\u548c\u5176\u4ed6\u4f8b\u5916\u6709\u4ec0\u9ebc\u4e0d\u540c\uff1f**<br \/>\nA1: NotImplementedError\u5c08\u9580\u7528\u65bc\u6307\u793a\u67d0\u500b\u529f\u80fd\u5c1a\u672a\u5be6\u73fe\uff0c\u800c\u5176\u4ed6\u4f8b\u5916\u5982ValueError\u6216TypeError\u5247\u7528\u65bc\u4e0d\u540c\u7684\u932f\u8aa4\u60c5\u6cc1\u3002<\/p>\n<p>**Q2: \u5982\u4f55\u8655\u7406NotImplementedError\uff1f**<br \/>\nA2: \u82e5\u5728\u8abf\u7528\u67d0\u500b\u529f\u80fd\u6642\u9047\u5230NotImplementedError\uff0c\u8acb\u6aa2\u67e5\u8a72\u529f\u80fd\u662f\u5426\u5df2\u7d93\u5be6\u73fe\uff0c\u4e26\u67e5\u770b\u662f\u5426\u6709\u9069\u7576\u7684\u5be6\u73fe\u3002<\/p>\n<p>**Q3: \u662f\u5426\u53ef\u4ee5\u81ea\u5b9a\u7fa9NotImplementedError\u7684\u6d88\u606f\uff1f**<br \/>\nA3: \u662f\u7684\uff0c\u60a8\u53ef\u4ee5\u5728\u62cb\u51faNotImplementedError\u6642\u63d0\u4f9b\u81ea\u5b9a\u7fa9\u7684\u932f\u8aa4\u6d88\u606f\uff0c\u4ee5\u4fbf\u65bc\u8abf\u8a66\u548c\u7406\u89e3\u4ee3\u78bc\u7684\u610f\u5716\u3002<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>NotImplementedError\u662fPython\u4e2d\u7684\u4e00\u500b\u4f8b\u5916\uff0c\u5b83\u8868\u793a\u67d0\u500b\u7279\u5b9a\u7684\u64cd\u4f5c\u6216\u529f\u80fd\u5c1a\u672a\u5be6\u73fe\u3002\u672c\u6587\u5c07\u4ecb\u7d39NotImplementedError\u7684\u529f\u80fd\u8207\u4f7f\u7528\u65b9\u5f0f\uff0c\u4ee5\u53ca\u5982\u4f55\u907f\u514d\u5b83\u7684\u51fa\u73fe\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-3615","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-Wj","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3615","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=3615"}],"version-history":[{"count":3,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3615\/revisions"}],"predecessor-version":[{"id":12782,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3615\/revisions\/12782"}],"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=3615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=3615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=3615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}