{"id":172,"date":"2021-04-10T12:02:44","date_gmt":"2021-04-10T03:02:44","guid":{"rendered":"http:\/\/www.agile-software.site\/?p=172"},"modified":"2021-04-17T20:53:13","modified_gmt":"2021-04-17T11:53:13","slug":"path%e3%82%aa%e3%83%96%e3%82%b8%e3%82%a7%e3%82%af%e3%83%88","status":"publish","type":"post","link":"https:\/\/agile-software.net\/?p=172","title":{"rendered":"Path\u30aa\u30d6\u30b8\u30a7\u30af\u30c8"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Pathlib\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3046<\/h2>\n\n\n\n<div class=\"wp-block-jin-gb-block-box-with-headline kaisetsu-box1\"><div class=\"kaisetsu-box1-title\">Path\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/div>\n<p>\u30d5\u30a1\u30a4\u30eb\u306e\u30d1\u30b9\u3092\u8868\u3059<\/p>\n<\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>from pathlib import Path\u3000\u3000\u3000#pathlib\u30e2\u30b8\u30e5\u30fc\u30eb\u304b\u3089Path\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u53d6\u308a\u8fbc\u3080\ncurrent = Path()\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000#\u5f15\u6570\u3092Path()\u306b\u6e21\u3055\u306a\u3044\u3068\u30d5\u30a1\u30a4\u30eb\u304c\u3042\u308b\u30d5\u30a9\u30eb\u30c0\u306ePath\u306b\u306a\u308b\nfor path in current.glob (&quot;*.jpg&quot;)     #jpg\u30d5\u30a1\u30a4\u30eb\u3092<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">glob\u30e1\u30bd\u30c3\u30c9<\/h3>\n\n\n\n<h3 class=\"wp-block-heading\">read_text\u30e1\u30bd\u30c3\u30c9<\/h3>\n\n\n\n<p>\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u306e\u5185\u5bb9\u3092\u8aad\u307f\u8fbc\u3080\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>from pathlib import Path\npath= Path(&quot;\u30c6\u30ad\u30b9\u30c81.txt&quot;)    #\u30c6\u30ad\u30b9\u30c81.txt\u306e\u30d1\u30b9\u3092\u53d6\u5f97\ntxt=path.read_text(encording=&#39;utf-8&#39;)     #\u30c6\u30ad\u30b9\u30c8\u306e\u5185\u5bb9\u3092txt\u5909\u6570\u306b\u5165\u308c\u308b<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">write_text\u30e1\u30bd\u30c3\u30c9<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>txt=&#39;\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304d\u8fbc\u3080\u305e&#39;\npath.write_text(txt,encording=&#39;utf-8&#39;)\u3000\u3000\u3000#txt\u5909\u6570\u306e\u5185\u5bb9\u3092\u66f8\u304d\u8fbc\u3080<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">is_dir\u30e1\u30bd\u30c3\u30c9<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>path.is_dir()     #\u30d5\u30a9\u30eb\u30c0\u3060\u3063\u305f\u3089True\u3092\u8fd4\u3059<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Pathlib\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3046 glob\u30e1\u30bd\u30c3\u30c9 read_text\u30e1\u30bd\u30c3\u30c9 \u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u306e\u5185\u5bb9\u3092\u8aad\u307f\u8fbc\u3080\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002 write_text\u30e1\u30bd\u30c3\u30c9 is_dir\u30e1\u30bd\u30c3\u30c9<\/p>\n","protected":false},"author":1,"featured_media":342,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jin_ogp_image_url":"","_jin_last_featured_id":0,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-172","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts\/172","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=172"}],"version-history":[{"count":2,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts\/172\/revisions"}],"predecessor-version":[{"id":343,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts\/172\/revisions\/343"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/media\/342"}],"wp:attachment":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}