{"id":204136,"date":"2025-05-29T13:26:22","date_gmt":"2025-05-29T05:26:22","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204136\/"},"modified":"2025-05-29T13:26:22","modified_gmt":"2025-05-29T05:26:22","slug":"%e5%8c%85%e5%90%ab%e7%94%b5%e6%b1%a0python-%e7%9a%84%e5%93%b2%e5%ad%a6","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204136\/","title":{"rendered":"\u201c\u5305\u542b\u7535\u6c60\u201dPython \u7684\u54f2\u5b66"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u201c\u5305\u542b\u7535\u6c60\u201dPython \u7684\u54f2\u5b66<\/h1>\n<p>\u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u201c\u5305\u542b\u7535\u6c60\u201dPython \u7684\u54f2\u5b66\u300b<\/span>\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span><\/span>\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241029\/17301928216720a5b5437a1.jpg\" class=\"aligncenter\"><\/p>\n<p>\u5728 Python \u793e\u533a\u4e2d\uff0c\u672f\u8bed <em>\u201c\u5305\u542b\u7684\u7535\u6c60\u201d<\/em> \u6307\u7684\u662f Python \u9644\u5e26\u4e86\u4e00\u4e2a\u975e\u5e38\u5168\u9762\u7684\u6807\u51c6\u5e93\uff0c\u5176\u4e2d\u5305\u62ec\u7528\u4e8e\u6267\u884c\u5404\u79cd\u5e38\u89c1\u4efb\u52a1\u7684\u6a21\u5757\u548c\u5305\u3002\u8fd9\u610f\u5473\u7740\u5bf9\u4e8e\u8bb8\u591a\u57fa\u672c\u7684\u7f16\u7a0b\u9700\u6c42\uff0c\u4e0d\u9700\u8981\u5b89\u88c5\u5916\u90e8\u5e93\uff0c\u56e0\u4e3a Python \u63d0\u4f9b\u4e86\u8bb8\u591a\u5185\u7f6e\u5de5\u5177\uff0c\u53ef\u4ee5\u8ba9\u60a8\u8f7b\u677e\u6267\u884c\u4efb\u52a1\u3002<\/p>\n<ol>\n<li>\n<p><strong>\u64cd\u4f5c\u7cfb\u7edf<\/strong><\/p>\n<ul>\n<li> <strong>\u63cf\u8ff0<\/strong>\uff1a\u63d0\u4f9b\u4e0e\u64cd\u4f5c\u7cfb\u7edf\u4ea4\u4e92\u7684\u65b9\u5f0f\u3002\u5b83\u5141\u8bb8\u64cd\u4f5c\u6587\u4ef6\u8def\u5f84\u3001\u8bbf\u95ee\u73af\u5883\u53d8\u91cf\u548c\u6267\u884c\u7cfb\u7edf\u547d\u4ee4\u7b49\u64cd\u4f5c\u3002<\/li>\n<li> <strong>\u4f7f\u7528\u793a\u4f8b<\/strong>\uff1aos.listdir() \u7528\u4e8e\u5217\u51fa\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>json<\/strong><\/p>\n<ul>\n<li> <strong>\u63cf\u8ff0<\/strong>\uff1a\u5141\u8bb8\u60a8\u4f7f\u7528 JSON\uff08JavaScript \u5bf9\u8c61\u8868\u793a\u6cd5\uff09\u683c\u5f0f\u7684\u6570\u636e\u3002\u8be5\u6a21\u5757\u5bf9\u4e8e\u5c06 Python \u5bf9\u8c61\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u4e3a JSON \u975e\u5e38\u6709\u7528\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002<\/li>\n<li> <strong>\u4f7f\u7528\u793a\u4f8b<\/strong>\uff1ajson.dumps() \u5c06 Python \u5bf9\u8c61\u8f6c\u6362\u4e3a JSON \u5b57\u7b26\u4e32\uff0cjson.loads() \u5c06 JSON \u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a Python \u5bf9\u8c61\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u65e5\u671f\u65f6\u95f4<\/strong><\/p>\n<ul>\n<li> <strong>\u63cf\u8ff0<\/strong>\uff1a\u63d0\u4f9b\u4ee5\u7b80\u5355\u65b9\u5f0f\u64cd\u4f5c\u65e5\u671f\u548c\u65f6\u95f4\u7684\u7c7b\u3002\u5b83\u5bf9\u4e8e\u6267\u884c\u65f6\u95f4\u8ba1\u7b97\u4ee5\u53ca\u683c\u5f0f\u5316\u65e5\u671f\u548c\u65f6\u95f4\u975e\u5e38\u6709\u7528\u3002<\/li>\n<li> <strong>\u4f7f\u7528\u793a\u4f8b<\/strong>\uff1adatetime.datetime.now() \u53ef\u4ee5\u83b7\u53d6\u5f53\u524d\u65e5\u671f\u548c\u65f6\u95f4\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u968f\u673a<\/strong><\/p>\n<ul>\n<li> <strong>\u63cf\u8ff0<\/strong>\uff1a\u63d0\u4f9b\u751f\u6210\u968f\u673a\u6570\u548c\u6267\u884c\u968f\u673a\u9009\u62e9\u7684\u51fd\u6570\uff0c\u8fd9\u5728\u6a21\u62df\u548c\u6e38\u620f\u7b49\u4efb\u52a1\u4e2d\u5f88\u6709\u7528\u3002<\/li>\n<li> <strong>\u4f7f\u7528\u793a\u4f8b<\/strong>\uff1arandom.randint(1, 10) \u751f\u6210 1 \u5230 10 \u4e4b\u95f4\u7684\u968f\u673a\u6574\u6570\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u518d<\/strong><\/p>\n<ul>\n<li> <strong>\u63cf\u8ff0<\/strong>\uff1a\u5141\u8bb8\u60a8\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u67e5\u627e\u3001\u66ff\u6362\u548c\u9a8c\u8bc1\u6587\u672c\u5b57\u7b26\u4e32\u4e2d\u7684\u6a21\u5f0f\u3002\u5b83\u5bf9\u4e8e\u6587\u672c\u5904\u7406\u548c\u6570\u636e\u9a8c\u8bc1\u975e\u5e38\u6709\u7528\u3002<\/li>\n<li> <strong>\u4f7f\u7528\u793a\u4f8b<\/strong>\uff1are.match() \u7528\u4e8e\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u7b26\u5408\u7279\u5b9a\u6a21\u5f0f\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u8fd9\u4e9b\u5305\u662f Python \u6807\u51c6\u5e93\u5f3a\u5927\u529f\u80fd\u7684\u793a\u4f8b\uff0c\u5b83\u4f7f\u60a8\u53ef\u4ee5\u8f7b\u677e\u521b\u5efa\u7a0b\u5e8f\uff0c\u800c\u65e0\u9700\u4e3a\u5e38\u89c1\u4efb\u52a1\u641c\u7d22\u5176\u4ed6\u5e93\u3002<\/p>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300a\u201c\u5305\u542b\u7535\u6c60\u201dPython \u7684\u54f2\u5b66\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n<p>      \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb\u5220\u9664<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u201c\u5305\u542b\u7535\u6c60\u201dPython \u7684\u54f2\u5b66&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-204136","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204136","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=204136"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204136\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}