{"id":49795,"date":"2024-12-03T12:43:52","date_gmt":"2024-12-03T04:43:52","guid":{"rendered":"https:\/\/fwq.ai\/blog\/49795\/"},"modified":"2024-12-03T12:43:52","modified_gmt":"2024-12-03T04:43:52","slug":"python3-%e5%a6%82%e4%bd%95%e5%b0%86%e5%88%97%e8%a1%a8%e4%b8%ad%e5%a4%9a%e4%b8%aa%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%ad%97%e5%85%b8%e5%90%88%e5%b9%b6%e4%b8%ba%e4%b8%80%e4%b8%aa%e5%ad%97%e5%85%b8%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/49795\/","title":{"rendered":"Python3 \u5982\u4f55\u5c06\u5217\u8868\u4e2d\u591a\u4e2a\u5b57\u7b26\u4e32\u5b57\u5178\u5408\u5e76\u4e3a\u4e00\u4e2a\u5b57\u5178\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Python3 \u5982\u4f55\u5c06\u5217\u8868\u4e2d\u591a\u4e2a\u5b57\u7b26\u4e32\u5b57\u5178\u5408\u5e76\u4e3a\u4e00\u4e2a\u5b57\u5178\uff1f<\/h1>\n<p>\u4f60\u5728\u5b66\u4e60\u76f8\u5173\u7684\u77e5\u8bc6\u5417\uff1f\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPython3 \u5982\u4f55\u5c06\u5217\u8868\u4e2d\u591a\u4e2a\u5b57\u7b26\u4e32\u5b57\u5178\u5408\u5e76\u4e3a\u4e00\u4e2a\u5b57\u5178\uff1f\u300b<\/span>\uff0c\u4e3b\u8981\u4ecb\u7ecd\u7684\u5185\u5bb9\u5c31\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u5982\u679c\u4f60\u60f3\u63d0\u5347\u81ea\u5df1\u7684\u5f00\u53d1\u80fd\u529b\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0\uff0c\u5927\u5bb6\u8981\u77e5\u9053\u7f16\u7a0b\u7406\u8bba\u57fa\u7840\u548c\u5b9e\u6218\u64cd\u4f5c\u90fd\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u54e6\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241104\/173068203067281caea4e39.jpg\" class=\"aligncenter\" title=\"Python3 \u5982\u4f55\u5c06\u5217\u8868\u4e2d\u591a\u4e2a\u5b57\u7b26\u4e32\u5b57\u5178\u5408\u5e76\u4e3a\u4e00\u4e2a\u5b57\u5178\uff1f\u63d2\u56fe\" alt=\"Python3 \u5982\u4f55\u5c06\u5217\u8868\u4e2d\u591a\u4e2a\u5b57\u7b26\u4e32\u5b57\u5178\u5408\u5e76\u4e3a\u4e00\u4e2a\u5b57\u5178\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>python3 \u5982\u4f55\u5c06\u5217\u8868\u4e2d\u591a\u4e2a\u5b57\u5178\u503c\u5408\u5e76\u4e3a\u4e00\u4e2a\u5b57\u5178<\/strong><\/p>\n<p>\u8981\u5c06\u5305\u542b\u591a\u4e2a\u5b57\u5178\u7684\u5217\u8868\u5408\u5e76\u4e3a\u4e00\u4e2a\u5b57\u5178\uff0c\u9700\u8981\u4f7f\u7528 [json.loads()](https:\/\/docs.python.org\/3\/library\/json.html#json.loads) \u51fd\u6570\u6765\u5c06\u6bcf\u4e2a\u5b57\u7b26\u4e32\u5b57\u5178\u8f6c\u6362\u4e3a\u5b57\u5178\u5bf9\u8c61\uff0c\u7136\u540e\u518d\u4f7f\u7528 [update()](https:\/\/docs.python.org\/3\/library\/stdtypes.html#dict.update) \u65b9\u6cd5\u5c06\u8fd9\u4e9b\u5b57\u5178\u9010\u4e2a\u5408\u5e76\u3002<\/p>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u6f14\u793a\u4e86\u5982\u4f55\u5b9e\u73b0\uff1a<\/p>\n<pre>import json\n\nd1 = {}\nl1 = [\"{'xvda': {'I\/O': {'r\/s': '0.33', 'await': '12.58', 'w\/s': '0.46'}, 'use_%': '32', 'total_G': '15G'}}\",\n       \"{'xvdf': {'I\/O': {'r\/s': '0.00', 'await': '20.23', 'w\/s': '0.01'}, 'use_%': '2', 'total_G': '100G'}}\",\n       \"{'xvdg': {'I\/O': {'r\/s': '0.02', 'await': '262.89', 'w\/s': '3.22'}, 'use_%': '64', 'total_G': '150G'}}\"]\n\nfor i in l1:\n    d1.update(json.loads(i))\n\nprint(d1)<\/pre>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0cl1 \u662f\u4e00\u4e2a\u5305\u542b\u4e09\u4e2a\u5b57\u7b26\u4e32\u5b57\u5178\u7684\u5217\u8868\u3002\u6211\u4eec\u4f7f\u7528 json.loads() \u5c06\u6bcf\u4e2a\u5b57\u7b26\u4e32\u5b57\u5178\u8f6c\u6362\u4e3a\u5b57\u5178\u5bf9\u8c61\uff0c\u7136\u540e\u4f7f\u7528 update() \u65b9\u6cd5\u5c06\u5176\u5408\u5e76\u5230 d1 \u5b57\u5178\u4e2d\u3002\u6700\u7ec8\uff0cd1 \u5c06\u5305\u542b\u5408\u5e76\u540e\u7684\u4e09\u4e2a\u5b57\u5178\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300aPython3 \u5982\u4f55\u5c06\u5217\u8868\u4e2d\u591a\u4e2a\u5b57\u7b26\u4e32\u5b57\u5178\u5408\u5e76\u4e3a\u4e00\u4e2a\u5b57\u5178\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python3 \u5982\u4f55\u5c06\u5217\u8868\u4e2d\u591a\u4e2a\u5b57\u7b26\u4e32\u5b57\u5178\u5408\u5e76\u4e3a\u4e00\u4e2a\u5b57\u5178\uff1f \u4f60\u5728\u5b66\u4e60\u76f8\u5173\u7684\u77e5\u8bc6\u5417\uff1f\u672c\u6587\u300aPython3 \u5982\u4f55\u5c06\u5217\u8868\u4e2d\u591a\u4e2a\u5b57\u7b26\u4e32\u5b57\u5178\u5408\u5e76\u4e3a\u4e00\u4e2a\u5b57\u5178\uff1f\u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u7684\u5185\u5bb9\u5c31\u6d89\u53ca\u5230\uff0c\u5982\u679c\u4f60\u60f3\u63d0\u5347\u81ea\u5df1\u7684\u5f00\u53d1\u80fd\u529b\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0\uff0c\u5927\u5bb6\u8981\u77e5\u9053\u7f16\u7a0b\u7406\u8bba\u57fa\u7840\u548c\u5b9e\u6218\u64cd\u4f5c\u90fd\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u54e6\uff01 python3 \u5982\u4f55\u5c06\u5217\u8868\u4e2d\u591a\u4e2a\u5b57\u5178\u503c\u5408\u5e76\u4e3a\u4e00\u4e2a\u5b57\u5178 \u8981\u5c06\u5305\u542b\u591a\u4e2a\u5b57\u5178\u7684\u5217\u8868\u5408\u5e76\u4e3a\u4e00\u4e2a\u5b57\u5178\uff0c\u9700\u8981\u4f7f\u7528 [json.loads()](https:\/\/docs.python.org\/3\/library\/json.html#json.loads) \u51fd\u6570\u6765\u5c06\u6bcf\u4e2a\u5b57\u7b26\u4e32\u5b57\u5178\u8f6c\u6362\u4e3a\u5b57\u5178\u5bf9\u8c61\uff0c\u7136\u540e\u518d\u4f7f\u7528 [update()](https:\/\/docs.python.org\/3\/library\/stdtypes.html#dict.update) \u65b9\u6cd5\u5c06\u8fd9\u4e9b\u5b57\u5178\u9010\u4e2a\u5408\u5e76\u3002 \u4ee5\u4e0b\u4ee3\u7801\u6f14\u793a\u4e86\u5982\u4f55\u5b9e\u73b0\uff1a import json d1 = {} l1 = [&#8220;{&#8216;xvda&#8217;: {&#8216;I\/O&#8217;: {&#8216;r\/s&#8217;: &#8216;0.33&#8217;, &#8216;await&#8217;: &#8216;12.58&#8217;, &#8216;w\/s&#8217;: &#8216;0.46&#8217;}, &#8216;use_%&#8217;: &#8217;32&#8217;, &#8216;total_G&#8217;: &#8217;15G&#8217;}}&#8221;, &#8220;{&#8216;xvdf&#8217;: {&#8216;I\/O&#8217;: {&#8216;r\/s&#8217;: &#8216;0.00&#8217;, &#8216;await&#8217;: &#8216;20.23&#8217;, &#8216;w\/s&#8217;: &#8216;0.01&#8217;}, &#8216;use_%&#8217;: &#8216;2&#8217;, &#8216;total_G&#8217;: &#8216;100G&#8217;}}&#8221;, &#8220;{&#8216;xvdg&#8217;: {&#8216;I\/O&#8217;: {&#8216;r\/s&#8217;: &#8216;0.02&#8217;, &#8216;await&#8217;: &#8216;262.89&#8217;, &#8216;w\/s&#8217;: &#8216;3.22&#8217;}, &#8216;use_%&#8217;: &#8217;64&#8217;, &#8216;total_G&#8217;: &#8216;150G&#8217;}}&#8221;] [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-49795","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49795","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=49795"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49795\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=49795"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=49795"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=49795"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}