<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>thaim</author_name>
  <author_url>https://blog.hatena.ne.jp/thaim/</author_url>
  <blog_title>Today I Learned</blog_title>
  <blog_url>https://thaim-til.hatenablog.jp/</blog_url>
  <categories>
    <anon>Python</anon>
  </categories>
  <description>ファイルパスが与えられたときに拡張子を除くファイル名を取得したいときがある。 今までは os.path のbasenameおよびsplitextを用いて取得していた。 import os file = os.path.basename(&quot;/path/to/file.txt&quot;) base = os.path.splitext(file) print(base[0]) ファイル名を取得するだけなら pathlib のstemを用いるともう少し簡単に実現できる。 from pathlib import Path path = Path(&quot;/path/to/file.txt&quot;) print(path.…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fthaim-til.hatenablog.jp%2Fentry%2F2023%2F10%2F12%2F222227&quot; title=&quot;pathlibのstemで拡張子を除くファイル名を取得する - Today I Learned&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2023-10-12 22:22:27</published>
  <title>pathlibのstemで拡張子を除くファイル名を取得する</title>
  <type>rich</type>
  <url>https://thaim-til.hatenablog.jp/entry/2023/10/12/222227</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
