{"id":205238,"date":"2025-05-29T10:10:51","date_gmt":"2025-05-29T02:10:51","guid":{"rendered":"https:\/\/server.hk\/cnblog\/205238\/"},"modified":"2025-05-29T10:10:51","modified_gmt":"2025-05-29T02:10:51","slug":"python-%e5%a6%82%e4%bd%95%e8%8e%b7%e5%8f%96%e5%bd%93%e5%89%8d%e6%9c%88%e7%ac%ac%e4%ba%94%e4%b8%aa%e5%b7%a5%e4%bd%9c%e6%97%a5%ef%bc%88%e6%8e%92%e9%99%a4%e8%8a%82%e5%81%87%e6%97%a5%ef%bc%89%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/205238\/","title":{"rendered":"Python \u5982\u4f55\u83b7\u53d6\u5f53\u524d\u6708\u7b2c\u4e94\u4e2a\u5de5\u4f5c\u65e5\uff08\u6392\u9664\u8282\u5047\u65e5\uff09\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Python \u5982\u4f55\u83b7\u53d6\u5f53\u524d\u6708\u7b2c\u4e94\u4e2a\u5de5\u4f5c\u65e5\uff08\u6392\u9664\u8282\u5047\u65e5\uff09\uff1f<\/h1>\n<p>\u5728IT\u884c\u4e1a\u8fd9\u4e2a\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u5f88\u5feb\u7684\u884c\u4e1a\uff0c\u53ea\u6709\u4e0d\u505c\u6b62\u7684\u5b66\u4e60\uff0c\u624d\u4e0d\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u5982\u679c\u4f60\u662f\u6587\u7ae0\u5b66\u4e60\u8005\uff0c\u90a3\u4e48\u672c\u6587\u300aPython \u5982\u4f55\u83b7\u53d6\u5f53\u524d\u6708\u7b2c\u4e94\u4e2a\u5de5\u4f5c\u65e5\uff08\u6392\u9664\u8282\u5047\u65e5\uff09\uff1f\u300b\u5c31\u5f88\u9002\u5408\u4f60\uff01\u672c\u7bc7\u5185\u5bb9\u4e3b\u8981\u5305\u62ec##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241126\/17326301926745d6b07efec.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>python \u5982\u4f55\u83b7\u53d6\u5f53\u524d\u6708\u7b2c\u4e94\u4e2a\u5de5\u4f5c\u65e5\uff08\u6392\u9664\u8282\u5047\u65e5\uff09<\/strong><\/p>\n<p><strong>\u95ee\u9898\u6458\u8981\uff1a<\/strong><\/p>\n<p>\u5f53\u6708\u7b2c\u4e94\u4e2a\u5de5\u4f5c\u65e5\u7684\u83b7\u53d6\u9700\u8981\u8df3\u8fc7\u8282\u5047\u65e5\uff0c\u8bf7\u95ee\u5728\u4e0d\u5b89\u88c5\u7b2c\u4e09\u65b9\u63d2\u4ef6\u7684\u60c5\u51b5\u4e0b\u6709\u7b80\u5355\u7684\u65b9\u6cd5\u5b9e\u73b0\u5417\uff1f<\/p>\n<p><strong>\u89e3\u7b54\uff1a<\/strong><\/p>\n<p><strong>\u6700\u7b80\u5355\u7684\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u7531\u4e8e\u8282\u5047\u65e5\u6570\u91cf\u6709\u9650\uff0c\u53ef\u4ee5\u8003\u8651\u521b\u5efa\u4e00\u4e2a\u5217\u8868\uff0c\u624b\u52a8\u8f93\u5165\u5f53\u5e74\u7684\u6240\u6709\u8282\u5047\u65e5\u3002\u7ef4\u62a4\u5de5\u4f5c\u91cf\u8f83\u5c0f\uff0c\u6bcf\u5e74\u53ea\u9700\u8981\u7ef4\u62a4\u4e00\u6b21\u3002<\/p>\n<p><strong>\u5176\u4ed6\u5de5\u4f5c\u65e5\u5224\u65ad\uff1a<\/strong><\/p>\n<p>\u5bf9\u4e8e\u5468\u516d\u548c\u5468\u65e5\uff0c\u53ef\u4ee5\u901a\u8fc7\u7a0b\u5e8f\u5224\u65ad\u3002python \u4e2d\u63d0\u4f9b datetime \u6a21\u5757\u6765\u5904\u7406\u65e5\u671f\u548c\u65f6\u95f4\u3002\u53ef\u4ee5\u57fa\u4e8e\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a<\/p>\n<ol>\n<li>\u4f7f\u7528 datetime.datetime \u51fd\u6570\u83b7\u53d6\u5f53\u6708\u7b2c\u4e00\u5929\u3002<\/li>\n<li>\u4f7f\u7528 weekday() \u65b9\u6cd5\u83b7\u53d6\u8fd9\u5929\u7684\u661f\u671f\u6570\uff080 \u4ee3\u8868\u661f\u671f\u4e00\uff0c6 \u4ee3\u8868\u661f\u671f\u65e5\uff09\u3002<\/li>\n<li>\u5faa\u73af\u904d\u5386\u76f4\u5230\u627e\u5230\u7b2c\u4e94\u4e2a\u5de5\u4f5c\u65e5\u3002<\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>import datetime\n\n# \u83b7\u53d6\u5f53\u6708\u7b2c\u4e00\u5929\nstart_date = datetime.datetime.now().replace(day=1)\n\n# \u67e5\u627e\u7b2c\u4e94\u4e2a\u5de5\u4f5c\u65e5\ncount = 0\nwhile count &lt; 5:\n    if start_date.weekday() not in [5, 6]:\n        count += 1\n    start_date += datetime.timedelta(days=1)\n\n# \u8f93\u51fa\u7b2c\u4e94\u4e2a\u5de5\u4f5c\u65e5\nprint(start_date.strftime(\"%Y-%m-%d\"))<\/pre>\n<p>\u672c\u7bc7\u5173\u4e8e\u300aPython \u5982\u4f55\u83b7\u53d6\u5f53\u524d\u6708\u7b2c\u4e94\u4e2a\u5de5\u4f5c\u65e5\uff08\u6392\u9664\u8282\u5047\u65e5\uff09\uff1f\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python \u5982\u4f55\u83b7\u53d6\u5f53\u524d\u6708\u7b2c\u4e94&#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-205238","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205238","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=205238"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205238\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=205238"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=205238"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=205238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}