{"id":1155,"date":"2023-03-24T18:05:53","date_gmt":"2023-03-24T09:05:53","guid":{"rendered":"https:\/\/fukugyouhistory.tokyo\/?p=1155"},"modified":"2023-03-24T20:01:11","modified_gmt":"2023-03-24T11:01:11","slug":"python%e3%80%80%e3%82%ab%e3%83%ac%e3%83%b3%e3%83%80%e3%83%bc%e8%a1%a8%e7%a4%ba%e3%83%bb%e6%99%82%e5%88%bb%e8%a8%88%e7%ae%97%e3%80%80%e5%ad%a6%e7%bf%92%e3%81%97%e3%81%a6%e3%81%bf%e3%81%9f","status":"publish","type":"post","link":"https:\/\/fukugyouhistory.tokyo\/?p=1155","title":{"rendered":"Python\u3000\u30ab\u30ec\u30f3\u30c0\u30fc\u8868\u793a\u30fb\u6642\u523b\u8a08\u7b97\u3000\u5b66\u7fd2\u3057\u3066\u307f\u305f"},"content":{"rendered":"\n<p>\u3053\u3053\u307e\u3067\u3001<a rel=\"noreferrer noopener\" href=\"https:\/\/fukugyouhistory.tokyo\/?p=1041\" target=\"_blank\">Python\u306e\u74b0\u5883\u69cb\u7bc9<\/a>\u3068<a href=\"https:\/\/fukugyouhistory.tokyo\/?p=1094\">Python\u306e\u30d5\u30a1\u30a4\u30eb\u64cd\u4f5c\u30fb\u30b0\u30e9\u30d5\u63cf\u753b<\/a>\u307e\u3067\u5b66\u7fd2\u3057\u3066\u304d\u307e\u3057\u305f\u3002<br>\u4eca\u56de\u306e\u8a18\u4e8b\u3067\u306f\u3001\u30ab\u30ec\u30f3\u30c0\u30fc\u8868\u793a\u30fb\u6642\u523b\u8a08\u7b97\u3092\u53d6\u308a\u4e0a\u3052\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u30ab\u30ec\u30f3\u30c0\u30fc\u8868\u793a<\/h2>\n\n\n\n<p>HTML\u30d5\u30a1\u30a4\u30eb\u3068\u3057\u3066\u30ab\u30ec\u30f3\u30c0\u30fc\u3092\u51fa\u529b\u3059\u308b\u30b3\u30fc\u30c9\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import calendar\n\n# HTML\u30d5\u30a1\u30a4\u30eb\u7528\u306e\u30ab\u30ec\u30f3\u30c0\u30fc\u4f5c\u6210\u306e\u6e96\u5099\nlc = calendar.HTMLCalendar()\n\n# \u9031\u306e\u59cb\u307e\u308a\u306f\u65e5\u66dc\u65e5\u306b\u8a2d\u5b9a\nlc.setfirstweekday(calendar.SUNDAY)\n\n# 2023\u5e74\u306e\u30ab\u30ec\u30f3\u30c0\u30fc\u3092\u6a2a4\u6708\u5206\u306e\u5e45\u3067\u4f5c\u6210\u3057\u3001HTML\u306e\u30b3\u30fc\u30c9\u3092\u51fa\u529b\nbody = lc.formatyear(2023, width=4)\n\n# HTML\u306e\u30d8\u30c3\u30c0\u3068\u30d5\u30c3\u30bf\u3092\u6307\u5b9a\nhtml = \"\"\"&lt;html&gt;&lt;head&gt;&lt;style&gt;\ntable { padding: 8px; }\nth { border-bottom: 1px solid gray; }\ntd { padding: 4px; vertical-align: top; }\n.sun { color: red; }\n.sat { color: blue; }\n&lt;\/style&gt;&lt;\/head&gt;&lt;body&gt;\"\"\" + body + \"\"\"\n&lt;\/body&gt;&lt;\/html&gt;\"\"\"\n\n# \u30d5\u30a1\u30a4\u30eb\u306b\u4fdd\u5b58\nfw = open(\"calendar2023.html\", \"wt\")\nfw.write(html)\n\nfw.close()<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" sizes=\"(max-width: 808px) 100vw, 808px\" src=\"https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-290.png\" alt=\"\" class=\"wp-image-1156\" width=\"405\" height=\"348\" srcset=\"https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-290.png 808w, https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-290-300x258.png 300w, https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-290-768x661.png 768w\" \/><\/figure>\n\n\n\n<p>\u305f\u3060\u5358\u7d14\u306b\u30ab\u30ec\u30f3\u30c0\u30fc\u3092\u6a19\u6e96\u51fa\u529b\u3059\u308b\u3060\u3051\u306a\u3089\u3001\u4e0b\u8a18\u306e\u901a\u308a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import calendar\n\n# \u9031\u306e\u59cb\u307e\u308a\u306f\u65e5\u66dc\u65e5\u306b\u8a2d\u5b9a\ncalendar.setfirstweekday(calendar.SUNDAY)\n\n# 2023\u5e741\u6708\u30ab\u30ec\u30f3\u30c0\u30fc\u3092\u8868\u793a\nprint(calendar.month(2023, 1))\n# 2023\u5e741\u6708\u30ab\u30ec\u30f3\u30c0\u30fc\u3092\u3001\u5e45=4\u3001\u9ad8\u3055=2\u306e\u8a2d\u5b9a\u3067\u8868\u793a\nprint(calendar.month(2023, 1, w=4, l=2))\n# 2023\u5e74\u30ab\u30ec\u30f3\u30c0\u30fc\u3092\u3001\u6a2a4\u6708\u5206\u306e\u5e45\u3067\u8868\u793a\nprint(calendar.calendar(2023, m=4))<\/code><\/pre>\n\n\n\n<p><img decoding=\"async\" width=\"200\" height=\"286\" class=\"wp-image-1186\" style=\"width: 200px;\" src=\"https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-303.png\" alt=\"\" srcset=\"https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-303.png 271w, https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-303-210x300.png 210w\" sizes=\"(max-width: 200px) 100vw, 200px\" \/>\u3000<img decoding=\"async\" width=\"450\" height=\"306\" class=\"wp-image-1187\" style=\"width: 450px;\" src=\"https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-304.png\" alt=\"\" srcset=\"https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-304.png 731w, https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-304-300x204.png 300w\" sizes=\"(max-width: 450px) 100vw, 450px\" \/><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u6642\u523b\u8a08\u7b97<\/h2>\n\n\n\n<p>\u30b3\u30fc\u30c9\u3092\u898b\u308b\u3068\u5206\u304b\u308b\u3068\u601d\u3044\u307e\u3059\u306e\u3067\u3001\u30b6\u30af\u30b6\u30af\u3063\u3068\u30b5\u30f3\u30d7\u30eb\u3092\u8f09\u305b\u3066\u3044\u304d\u307e\u3059\u3002<br>\u578b\u5f0f\u304c\u300cdatetime\u300d\u300cdate\u300d\u300ctime\u300d\u300ctimedelta\u300d\u3068\u5e7e\u3064\u304b\u51fa\u3066\u304d\u307e\u3059\u304c\u3001<br>\u6271\u3046\u3082\u306e\u304c\u300c\u65e5\u6642\u300d\u300c\u65e5\u4ed8\u300d\u300c\u6642\u9593\u300d\u300c\u6642\u9593\u306e\u5dee\u5206\u300d\u3068\u8a00\u3046\u3053\u3068\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import datetime\n\n# \u73fe\u5728\u6642\u523b\u306e\u53d6\u5f97\ndt_now = datetime.datetime.now()\nprint(dt_now)\n# \u578b\u5f0f\u306e\u78ba\u8a8d\nprint(type(dt_now))\n\nprint(dt_now.year)\nprint(dt_now.hour)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" sizes=\"(max-width: 483px) 100vw, 483px\" src=\"https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-293.png\" alt=\"\" class=\"wp-image-1162\" width=\"404\" height=\"222\" srcset=\"https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-293.png 483w, https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-293-300x165.png 300w\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>import datetime\n\n# \u6307\u5b9a\u6642\u523b\ndt = datetime.datetime(2018, 2, 1, 12, 15, 30, 2000)\nprint(dt)\nprint(dt.minute)\nprint(dt.microsecond)\n\n# \u7701\u7565\u3057\u305f\u5834\u5408\u30010\u304c\u4ee3\u5165\u3055\u308c\u307e\u3059\ndt = datetime.datetime(2018, 2, 1)\nprint(dt)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" sizes=\"(max-width: 482px) 100vw, 482px\" src=\"https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-294.png\" alt=\"\" class=\"wp-image-1163\" width=\"405\" height=\"243\" srcset=\"https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-294.png 482w, https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-294-300x180.png 300w\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>import datetime\n\n# \u73fe\u5728\u6642\u523b\u306e\u53d6\u5f97\ndt_now = datetime.datetime.now()\n\n# \u578b\u5f0f datetime\nprint(dt_now)\nprint(type(dt_now))\n\n# \u578b\u5f0fdate\u3078\u306e\u5909\u63db\nprint(dt_now.date())\nprint(type(dt_now.date()))<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" sizes=\"(max-width: 484px) 100vw, 484px\" src=\"https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-295.png\" alt=\"\" class=\"wp-image-1164\" width=\"404\" height=\"251\" srcset=\"https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-295.png 484w, https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-295-300x187.png 300w\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>import datetime\n\n# \u4eca\u65e5\u306e\u65e5\u4ed8\u306e\u53d6\u5f97\nd_today = datetime.date.today()\nprint(d_today)\nprint(type(d_today))\n\nprint(d_today.year)\nprint(d_today.month)\nprint(d_today.day)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" sizes=\"(max-width: 481px) 100vw, 481px\" src=\"https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-296.png\" alt=\"\" class=\"wp-image-1165\" width=\"405\" height=\"241\" srcset=\"https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-296.png 481w, https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-296-300x178.png 300w\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>import datetime\n\n# \u6307\u5b9a\u65e5\u4ed8\u3001\u7701\u7565\u4e0d\u53ef\nd = datetime.date(2018, 2, 1)\nprint(d)\n\nprint(d.year)\nprint(d.month)\nprint(d.day)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" sizes=\"(max-width: 480px) 100vw, 480px\" src=\"https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-297.png\" alt=\"\" class=\"wp-image-1166\" width=\"404\" height=\"209\" srcset=\"https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-297.png 480w, https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-297-300x155.png 300w\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>import datetime\n\n# \u6307\u5b9a\u6642\u523b\nt = datetime.time(12, 15, 30, 2000)\nprint(t)\nprint(type(t))\n\nprint(t.hour)\nprint(t.minute)\nprint(t.second)\nprint(t.microsecond)\n\n# \u7701\u7565\u3057\u305f\u5834\u5408\u30010\u304c\u4ee3\u5165\u3055\u308c\u307e\u3059\nt = datetime.time(12, 15)\nprint(t)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" sizes=\"(max-width: 483px) 100vw, 483px\" src=\"https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-298.png\" alt=\"\" class=\"wp-image-1167\" width=\"403\" height=\"331\" srcset=\"https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-298.png 483w, https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-298-300x247.png 300w\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>import datetime\n\ndt1 = datetime.datetime(2023, 2, 11, 6, 25, 15, 4000)\ndt2 = datetime.datetime(2023, 2, 12, 12, 15, 30, 2000)\n\n# \u6642\u9593\u306e\u5dee\u5206\ntd = dt2- dt1\nprint(td)\nprint(type(td))\n\nprint(td.days)\nprint(td.seconds)\nprint(td.microseconds)\n\n# \u30c8\u30fc\u30bf\u30eb\u306e\u79d2\u6570\nprint(td.total_seconds())\nprint((60 * 60 * 24) * td.days + td.seconds + 0.000001 * td.microseconds)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" sizes=\"(max-width: 625px) 100vw, 625px\" src=\"https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-299.png\" alt=\"\" class=\"wp-image-1169\" width=\"405\" height=\"272\" srcset=\"https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-299.png 625w, https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-299-300x201.png 300w\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>import datetime\n\n# \u4eca\u65e5\u306e\u65e5\u4ed8\u306e\u53d6\u5f97\uff08\u578b\u5f0fdate\uff09\nd_today = datetime.date.today()\nprint(d_today)\n\n# \u5dee\u52061\u9031\u9593\ntd_1w = datetime.timedelta(weeks=1)\nprint(d_today - td_1w)\n\n# \u5dee\u520610\u65e5\u9593\ntd_10d = datetime.timedelta(days=10)\nprint(d_today - td_10d)\n\n# \u73fe\u5728\u6642\u523b\u306e\u53d6\u5f97\uff08\u578b\u5f0fdatetime\uff09\ndt_now = datetime.datetime.now()\nprint(dt_now)\n\n# \u5dee\u520650\u5206\u9593\ntd_50m = datetime.timedelta(minutes=50)\nprint(dt_now - td_50m)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" sizes=\"(max-width: 497px) 100vw, 497px\" src=\"https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-300.png\" alt=\"\" class=\"wp-image-1170\" width=\"405\" height=\"354\" srcset=\"https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-300.png 497w, https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-300-300x262.png 300w\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>import datetime\n\n# \u6587\u5b57\u5217\u306e\u65e5\u4ed8\ndate_str = '2018\u5e742\u67081\u65e5'\ndate_format = '%Y\u5e74%m\u6708%d\u65e5'\ntd_10_d = datetime.timedelta(days=10)\nprint(date_str)\nprint(type(date_str))\n\n# \u578b\u5f0fdatetime\u3078\u306e\u5909\u63db\ndate_dt = datetime.datetime.strptime(date_str, date_format)\nprint(date_dt)\nprint(type(date_dt))\n\ndate_dt_new = date_dt - td_10_d\n\n# \u6587\u5b57\u5217\u306e\u578b\u3078\u5909\u63db\ndate_str_new = date_dt_new.strftime(date_format)\n\nprint(date_str_new)\nprint(type(date_str_new))<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" sizes=\"(max-width: 499px) 100vw, 499px\" src=\"https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-301.png\" alt=\"\" class=\"wp-image-1173\" width=\"404\" height=\"399\" srcset=\"https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-301.png 499w, https:\/\/fukugyouhistory.tokyo\/wp-content\/uploads\/2023\/03\/image-301-300x296.png 300w\" \/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u4e00\u65e6\u3001\u9577\u304f\u306a\u3063\u3066\u304d\u307e\u3057\u305f\u306e\u3067\u3001\u3053\u3053\u307e\u3067\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3053\u307e\u3067\u3001Python\u306e\u74b0\u5883\u69cb\u7bc9\u3068Python\u306e\u30d5\u30a1\u30a4\u30eb\u64cd\u4f5c\u30fb\u30b0\u30e9\u30d5\u63cf\u753b\u307e\u3067\u5b66\u7fd2\u3057\u3066\u304d\u307e\u3057\u305f\u3002\u4eca\u56de\u306e\u8a18\u4e8b\u3067\u306f\u3001\u30ab\u30ec\u30f3\u30c0\u30fc\u8868\u793a\u30fb\u6642\u523b\u8a08\u7b97\u3092\u53d6\u308a\u4e0a\u3052\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":{"0":"post-1155","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-python"},"_links":{"self":[{"href":"https:\/\/fukugyouhistory.tokyo\/index.php?rest_route=\/wp\/v2\/posts\/1155","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fukugyouhistory.tokyo\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fukugyouhistory.tokyo\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fukugyouhistory.tokyo\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fukugyouhistory.tokyo\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1155"}],"version-history":[{"count":10,"href":"https:\/\/fukugyouhistory.tokyo\/index.php?rest_route=\/wp\/v2\/posts\/1155\/revisions"}],"predecessor-version":[{"id":1188,"href":"https:\/\/fukugyouhistory.tokyo\/index.php?rest_route=\/wp\/v2\/posts\/1155\/revisions\/1188"}],"wp:attachment":[{"href":"https:\/\/fukugyouhistory.tokyo\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fukugyouhistory.tokyo\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fukugyouhistory.tokyo\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}