{"id":176367,"date":"2023-08-02T15:52:20","date_gmt":"2023-08-02T07:52:20","guid":{"rendered":"http:\/\/www.idc.net\/help\/176367\/"},"modified":"2023-08-02T15:52:20","modified_gmt":"2023-08-02T07:52:20","slug":"%e5%90%8e%e6%b5%aa%e4%ba%91python%e6%95%99%e7%a8%8b%ef%bc%9apython-chainmap%e7%9a%84%e7%ae%a1%e7%90%86%e7%94%a8%e6%b3%95","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/176367\/","title":{"rendered":"\u540e\u6d6a\u4e91Python\u6559\u7a0b\uff1apython ChainMap\u7684\u7ba1\u7406\u7528\u6cd5"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/oss.py.cn\/pycn\/upload\/image\/781\/663\/953\/1629180781612263.png\" class=\"aligncenter\"><\/p>\n<p><strong>\u8bf4\u660e\uff1a<\/strong><\/p>\n<p style=\"line-height: 2em\">1\u3001ChainMap\u7684\u4e3b\u8981\u7528\u4f8b\u662f\u63d0\u4f9b\u4e00\u79cd\u6709\u6548\u7684\u65b9\u6cd5\u6765\u7ba1\u7406\u591a\u4e2a\u8303\u56f4\u6216\u4e0a\u4e0b\u6587\uff0c\u5e76\u5904\u7406\u91cd\u590d\u952e\u7684\u8bbf\u95ee\u4f18\u5148\u7ea7\u3002<\/p>\n<p style=\"line-height: 2em\">2\u3001\u5f53\u6709\u591a\u4e2a\u5b58\u50a8\u91cd\u590d\u952e\u7684\u5b57\u5178\u8bbf\u95ee\u5b83\u4eec\u7684\u987a\u5e8f\u65f6\uff0c\u8fd9\u4e2a\u529f\u80fd\u975e\u5e38\u6709\u7528\u3002<\/p>\n<p style=\"line-height: 2em\">\u5728ChainMap\u6587\u6863\u4e2d\u627e\u5230\u4e00\u4e2a\u7ecf\u5178\u7684\u4f8b\u5b50\uff0c\u5b83\u6a21\u62dfPython\u5982\u4f55\u5206\u6790\u4e0d\u540c\u547d\u540d\u7a7a\u95f4\u4e2d\u7684\u53d8\u91cf\u540d\u79f0\u3002<\/p>\n<p style=\"line-height: 2em\">\u5f53Python\u641c\u7d22\u540d\u79f0\u65f6\uff0c\u5b83\u4f1a\u4f9d\u6b21\u641c\u7d22\u5f53\u5730\u3001\u5168\u5c40\u548c\u5185\u7f6e\u7684\u529f\u80fd\u57df\uff0c\u76f4\u5230\u627e\u5230\u76ee\u6807\u540d\u79f0\u3002Python\u4f5c\u7528\u57df\u662f\u5c06\u540d\u79f0\u6620\u5c04\u5230\u5bf9\u8c61\u7684\u5b57\u5178\u3002<\/p>\n<p style=\"line-height: 2em\">\u4e3a\u4e86\u6a21\u62dfPython\u7684\u5185\u90e8\u641c\u7d22\u94fe\uff0c\u53ef\u4ee5\u4f7f\u7528\u94fe\u6620\u5c04\u3002<\/p>\n<p style=\"line-height: 2em\"><strong>\u5b9e\u4f8b<\/strong><\/p>\n<pre>&gt;&gt;&gt;&nbsp;import&nbsp;builtins\n&nbsp;\n&gt;&gt;&gt;&nbsp;#&nbsp;Shadow&nbsp;input&nbsp;with&nbsp;a&nbsp;global&nbsp;name\n&gt;&gt;&gt;&nbsp;input&nbsp;=&nbsp;42\n&nbsp;\n&gt;&gt;&gt;&nbsp;pylookup&nbsp;=&nbsp;ChainMap(locals(),&nbsp;globals(),&nbsp;vars(builtins))\n&nbsp;\n&gt;&gt;&gt;&nbsp;#&nbsp;Retrieve&nbsp;input&nbsp;from&nbsp;the&nbsp;global&nbsp;namespace\n&gt;&gt;&gt;&nbsp;pylookup[\"input\"]\n42\n&nbsp;\n&gt;&gt;&gt;&nbsp;#&nbsp;Remove&nbsp;input&nbsp;from&nbsp;the&nbsp;global&nbsp;namespace\n&gt;&gt;&gt;&nbsp;del&nbsp;globals()[\"input\"]\n&nbsp;\n&gt;&gt;&gt;&nbsp;#&nbsp;Retrieve&nbsp;input&nbsp;from&nbsp;the&nbsp;builtins&nbsp;namespace\n&gt;&gt;&gt;&nbsp;pylookup[\"input\"]\n&lt;built-in&nbsp;function&nbsp;input&gt;<\/pre>\n<p style=\"line-height: 2em\">\u4ee5\u4e0a\u5c31\u662fpython ChainMap\u7684\u7ba1\u7406\u7528\u6cd5\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u6709\u6240\u5e2e\u52a9\u3002<span style=\"font-size: 16px\">\u66f4\u591aPython\u5b66\u4e60\u6307\u8def\uff1a<\/span><span style=\"font-size: 16px\">\u540e\u6d6a\u4e91python\u6559\u7a0b<\/span><\/p>\n<p style=\"line-height: 2em\"><span style=\"font-size: 14px\">\u672c\u6587\u6559\u7a0b\u64cd\u4f5c\u73af\u5883\uff1awindows7\u7cfb\u7edf\u3001Python 3.9.1\uff0cDELL G3\u7535\u8111\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8bf4\u660e\uff1a 1\u3001ChainMap\u7684\u4e3b\u8981\u7528\u4f8b\u662f\u63d0\u4f9b\u4e00\u79cd\u6709\u6548\u7684\u65b9\u6cd5\u6765\u7ba1\u7406\u591a\u4e2a\u8303\u56f4\u6216\u4e0a\u4e0b\u6587\uff0c\u5e76\u5904\u7406\u91cd\u590d\u952e\u7684\u8bbf\u95ee\u4f18\u5148\u7ea7\u3002  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":176368,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182397],"tags":[],"class_list":["post-176367","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/176367","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=176367"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/176367\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media\/176368"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=176367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=176367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=176367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}