{"id":1527,"date":"2022-01-22T17:56:37","date_gmt":"2022-01-22T08:56:37","guid":{"rendered":"https:\/\/aiacademy.jp\/media\/?p=1527"},"modified":"2024-08-06T14:57:17","modified_gmt":"2024-08-06T05:57:17","slug":"%e3%80%90%e5%88%9d%e5%bf%83%e8%80%85%e5%90%91%e3%81%91%e3%80%91python-os-path-join-%e3%81%a8%e3%81%af%ef%bc%9f%e3%83%91%e3%82%b9%e3%82%92%e7%b5%90%e5%90%88%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/aiacademy.jp\/media\/?p=1527","title":{"rendered":"\u3010\u521d\u5fc3\u8005\u5411\u3051\u3011Python os.path.join() \u3068\u306f\uff1f\u30d1\u30b9\u3092\u7d50\u5408\u3059\u308b\u65b9\u6cd5\u3092\u5b66\u307c\u3046\uff01"},"content":{"rendered":"<div id=\"sgb-css-id-1\">\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button has-custom-font-size is-style-fill has-medium-font-size\"><a class=\"wp-block-button__link has-vivid-green-cyan-background-color has-background wp-element-button\" href=\"https:\/\/lin.ee\/3E4GzWk\" rel=\"nofollow noopener\" target=\"_blank\">LINE\u53cb\u3060\u3061\u767b\u9332 \u25b6 Python\u30b3\u30fc\u30b9 \u25b6 \u53d7\u8b1b\u5272\u5f15\u30af\u30fc\u30dd\u30f3 \u7121\u6599\u52d5\u753b<\/a><\/div>\n<\/div>\n<\/div>\n\n\n<h1 class=\"wp-block-heading\" id=\"i-0\">os.path.join() \u3068\u306f<\/h1>\n\n\n\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306fPython\u3067\u30d1\u30b9\u7d50\u5408\u3059\u308b\u969b\u306b\u7528\u3044\u3089\u308c\u308b<code>os.path.join()<\/code>\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u7686\u69d8\u306f\u3001Python\u3067\u30d1\u30b9\u3092\u7d50\u5408\u3059\u308b\u6642\u306b\u3001\u6587\u5b57\u5217\u540c\u58eb\u3092\u7d50\u5408\u3057\u3066\u3044\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002\u6587\u5b57\u5217\u7d50\u5408\u3067\u30d1\u30b9\u3092\u3064\u306a\u304e\u5408\u308f\u305b\u308b\u3068\u3001\u4e0d\u6b63\u306a\u30d1\u30b9\u306b\u306a\u308b\u3053\u3068\u3082\u3042\u308a\u3001\u30a8\u30e9\u30fc\u306e\u539f\u56e0\u306b\u306a\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4eca\u56de\u306f\u3001<meta charset=\"utf-8\"><code>os.path.join()<\/code>\u3092\u6d3b\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u7c21\u5358\u306b\u30d1\u30b9\u3092\u7d50\u5408\u3067\u304d\u308b\u65b9\u6cd5\u3092\u5b66\u3073\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"i-1\">\u30d1\u30b9\u3092\u7d50\u5408\u3059\u308b<\/h1>\n\n\n\n<p><code>os.path.join()<\/code>\u3092\u7528\u3044\u308b\u3053\u3068\u3067\u3001\u5f15\u6570\u306b\u6e21\u3057\u305f2\u3064\u306e\u6587\u5b57\u5217\u3092\u7d50\u5408\u3057\u30011\u3064\u306e\u30d1\u30b9\u306b\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import os\n# log \u3068 sample.log\u3092\u7d50\u5408\u3057\u3001log\/sample.log \u3068\u3044\u3046\u30d1\u30b9\u3092\u4f5c\u308b\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\njoin_path = os.path.join(\"log\", \"sample.log\")\nprint(join_path)<\/code><\/pre>\n\n\n\n<p><strong>\u51fa\u529b\u7d50\u679c<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>log\/sample.log<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"i-2\">2\u3064\u4ee5\u4e0a\u306e\u30d1\u30b9\u3092\u7d50\u5408\u3059\u308b<\/h1>\n\n\n\n<p>os.path.join()\u306b\u306f2\u3064\u4ee5\u4e0a\u3092\u6e21\u3059\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u4f8b\u3048\u3070\u3001Google Colab\u3092\u7528\u3044\u3066\u3001\u30d5\u30a1\u30a4\u30eb\u51e6\u7406\u3092\u3059\u308b\u5834\u5408\u306b\u3001\u3001content\u304c\u30ab\u30ec\u30f3\u30c8\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u306a\u308b\u305f\u3081\u3001\u30d5\u30a1\u30a4\u30eb\u51e6\u7406\u4ee5\u524d\u3067\u30d1\u30b9\u95a2\u9023\u3067\u8e93\u3044\u3066\u3057\u307e\u3046\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<br>\u305d\u306e\u3088\u3046\u306a\u5834\u5408\u306b\u3001\u4e8b\u524d\u306b\u5b9a\u6570CDIR\u306a\u3069\u3092os.getcwd()\u3092\u7528\u3044\u3066\u30ab\u30ec\u30f3\u30c8\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u683c\u7d0d\u3057\u3066\u304a\u304d\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u3066\u304a\u304f\u3068\u30d5\u30a1\u30a4\u30eb\u51e6\u7406\u3092\u884c\u3046\u969b\u306b\u3001\u30d1\u30b9\u5468\u308a\u3067\u8e93\u304f\u3053\u3068\u306f\u6e1b\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CDIR = os.getcwd() # google colab\u306e\u5834\u5408\u3001\/content\/ \u304c\u30ab\u30ec\u30f3\u30c8\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u6307\u3057\u307e\u3059\u3002\nimage_file = os.path.join(CDIR, \"img\", \"sample.png\")\nprint(image_file)<\/code><\/pre>\n\n\n\n<p>\u203bcontent\u914d\u4e0b\u306b\u3001img\u30d5\u30a9\u30eb\u30c0\u304c\u3042\u308a\u3001\u305d\u306e\u914d\u4e0b\u306b\u3001\u4f55\u3089\u304b\u306e\u753b\u50cf\u30d5\u30a1\u30a4\u30ebsample.png\u304c\u3042\u308b\u3053\u3068\u3092\u60f3\u5b9a\u3057\u305f\u5834\u5408\u306eimage_file\u306e\u5b9a\u7fa9<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"i-3\">\u30ea\u30b9\u30c8\u5f62\u5f0f\u3067\u30d1\u30b9\u3092\u7d50\u5408\u3059\u308b<\/h1>\n\n\n\n<p><code>os.path.join()<\/code>\u3092\u7528\u3044\u305a\u306b\u3001\u30d1\u30b9\u3092\u793a\u3059\u5909\u6570\u3092\u5b9a\u7fa9\u3057\u7d50\u5408\u3059\u308b\u3053\u3068\u3067\u540c\u69d8\u306b\u5b9f\u73fe\u3067\u304d\u307e\u3059\u304c\u3001\u6587\u5b57\u5217\u7d50\u5408\u306e\u5834\u5408\u3001\u30d1\u30b9\u304c\u3046\u307e\u304f\u8868\u73fe\u3067\u304d\u306a\u3044\u4e0d\u6b63\u306a\u30d1\u30b9\u306b\u306a\u308b\u3053\u3068\u3082\u8003\u3048\u3089\u308c\u308b\u305f\u3081\u3001<code>os.path.join()<\/code>\u3092\u7528\u3044\u3066\u7d50\u5408\u3059\u308b\u306e\u304c\u826f\u3044\u3067\u3057\u3087\u3046\u3002\u307e\u305f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30ea\u30b9\u30c8\u306e\u8981\u7d20\u3054\u3068\u306b\u30d1\u30b9\u304c\u683c\u7d0d\u3055\u308c\u305f\u5834\u5408\u3067\u3082\u3001<code>os.path.join()<\/code>\u306e\u5f15\u6570\u306b<strong>*<\/strong>\uff08\u30a2\u30b9\u30bf\u30ea\u30b9\u30af\uff09\u3092\u52a0\u3048\u308b\u3060\u3051\u3067\u3001\u7c21\u5358\u306b\u30d1\u30b9\u3092\u4f5c\u6210\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>path_lists = [\"var\", \"www\", \"html\", \"index.html\"] \njoin_path = os.path.join(*path_lists)\nprint(join_path)<\/code><\/pre>\n\n\n\n<p>\u51fa\u529b\u7d50\u679c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var\/www\/html\/index.html<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"i-4\">\u88dc\u8db3\uff08pathlib\u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u95a2\u3057\u3066\uff09<\/h1>\n\n\n\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u8a73\u7d30\u306f\u89e3\u8aac\u3057\u307e\u305b\u3093\u304c\u3001<meta charset=\"utf-8\">pathlib\u30e2\u30b8\u30e5\u30fc\u30eb\u306ePath\u3092\u7528\u3044\u3066\u3082\u540c\u69d8\u306b\u30d1\u30b9\u7d50\u5408\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u3061\u3089\u3082\u5408\u308f\u305b\u3066\u77e5\u3063\u3066\u304a\u304f\u3068\u826f\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from pathlib import Path\njoin_path = Path(\"log\", \"sample.log\")\nprint(join_path)<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"toc\">    <div id=\"toc_container\" class=\"sgb-toc--no-bullets js-smooth-scroll\" data-dialog-title=\"Table of Contents\">\n      <p class=\"toc_title\">\u76ee\u6b21 <\/p>\n      <ul class=\"toc_list\">  <li class=\"first\">    <a href=\"#i-0\">os.path.join() \u3068\u306f<\/a>  <\/li>  <li>    <a href=\"#i-1\">\u30d1\u30b9\u3092\u7d50\u5408\u3059\u308b<\/a>  <\/li>  <li>    <a href=\"#i-2\">2\u3064\u4ee5\u4e0a\u306e\u30d1\u30b9\u3092\u7d50\u5408\u3059\u308b<\/a>  <\/li>  <li>    <a href=\"#i-3\">\u30ea\u30b9\u30c8\u5f62\u5f0f\u3067\u30d1\u30b9\u3092\u7d50\u5408\u3059\u308b<\/a>  <\/li>  <li class=\"last\">    <a href=\"#i-4\">\u88dc\u8db3\uff08pathlib\u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u95a2\u3057\u3066\uff09<\/a>    <ul class=\"menu_level_1\">      <li class=\"first last\">        <a href=\"#i-5\">\u304a\u308f\u308a\u306b<\/a>      <\/li>    <\/ul>  <\/li><\/ul>\n      \n    <\/div><\/div><div class=\"toc\"><p><\/p>\n<\/div><h2 class=\"wp-block-heading\" id=\"i-5\">\u304a\u308f\u308a\u306b<\/h2>\n\n\n\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001os.path.join() \u3092\u7528\u3044\u3066\u30d1\u30b9\u3092\u7d50\u5408\u3059\u308b\u65b9\u6cd5\u3092\u5b66\u3073\u307e\u3057\u305f\u3002Python\u3092\u52b9\u7387\u3088\u304f\u5b66\u3076\u306b\u306f\u3001\u73fe\u5f79\u306e\u30c7\u30fc\u30bf\u30b5\u30a4\u30a8\u30f3\u30c6\u30a3\u30b9\u30c8\u3084\u6a5f\u68b0\u5b66\u7fd2\u30a8\u30f3\u30b8\u30cb\u30a2\u306b\u8cea\u554f\u3057\u653e\u984c\u304b\u3064\u3001\u4f53\u7cfb\u7684\u306b\u5b66\u3079\u308b\u52d5\u753b\u30b3\u30f3\u30c6\u30f3\u30c4\u3067\u30c7\u30fc\u30bf\u5206\u6790\u6280\u8853\u3092\u5b66\u3073\u305f\u3044\u65b9\u306f\u3001\u30aa\u30f3\u30e9\u30a4\u30f3\u3067\u597d\u304d\u306a\u6642\u9593\u306b\u52c9\u5f37\u3067\u304d\u308b<a href=\"https:\/\/aiacademy.jp\/bootcamp\">AI Academy Bootcamp<\/a>\u304c\u30aa\u30b9\u30b9\u30e1\u3067\u3059\u3002<meta charset=\"utf-8\"><a href=\"https:\/\/aiacademy.jp\/bootcamp\">AI Academy Bootcamp<\/a>\u3067\u306f\u3001\u8b1b\u5e2b\u304b\u3089\u30b3\u30fc\u30c9\u30ec\u30d3\u30e5\u30fc\u3082\u3057\u653e\u984c\u306a\u306e\u3067\u3001\u30b3\u30fc\u30c9\u306e\u6dfb\u524a\u3082\u884c\u3044\u306a\u304c\u3089\u3088\u308a\u5b9f\u52d9\u30ec\u30d9\u30eb\u306e\u30b3\u30fc\u30c9\u3092\u66f8\u3051\u308b\u3088\u3046\u306b\u7fd2\u5f97\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/aiacademy.jp\/bootcamp\/\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"341\" src=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi-1024x341.png\" alt=\"\" class=\"wp-image-691\" srcset=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi-1024x341.png 1024w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi-300x100.png 300w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi-768x256.png 768w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi-940x313.png 940w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi.png 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\"><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>os.path.join() \u3068\u306f \u3053\u306e\u8a18\u4e8b\u3067\u306fPython\u3067\u30d1\u30b9\u7d50\u5408\u3059\u308b\u969b\u306b\u7528\u3044\u3089\u308c\u308bos.path.join()\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002 \u7686\u69d8\u306f\u3001Python\u3067\u30d1\u30b9\u3092\u7d50\u5408\u3059\u308b\u6642\u306b\u3001\u6587\u5b57\u5217\u540c\u58eb\u3092\u7d50\u5408\u3057\u3066\u3044\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002\u6587 &#8230; <\/p>\n","protected":false},"author":1,"featured_media":1531,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[85,171],"tags":[],"class_list":{"0":"post-1527","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python","8":"category-171"},"_links":{"self":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/1527","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1527"}],"version-history":[{"count":5,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/1527\/revisions"}],"predecessor-version":[{"id":4698,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/1527\/revisions\/4698"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/media\/1531"}],"wp:attachment":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1527"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1527"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1527"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}