You could just .split it:
>>> Path('logs/date.log.txt').stem.split('.')[0]
'date'
os.path works just as well:
>>> os.path.basename('logs/date.log.txt').split('.')[0]
'date'
It passes all of the tests:
In [11]: all(Path(k).stem.split('.')[0] == v for k, v in {
....: 'a': 'a',
....: 'a.txt': 'a',
....: 'archive.tar.gz': 'archive',
....: 'directory/file': 'file',
....: 'd.x.y.z/f.a.b.c': 'f',
....: 'logs/date.log.txt': 'date'
....: }.items())
Out[11]: True
Answer from Blender on Stack OverflowGitHub
github.com › torproject › stem
GitHub - torproject/stem: Python controller library for Tor · GitHub
Stem is a Python controller library for Tor.
Author: torproject
Python
docs.python.org › 3 › library › pathlib.html
pathlib — Object-oriented filesystem paths
>>> p = PurePath('/usr/bin/python3') >>> p.parts ('/', 'usr', 'bin', 'python3') >>> p = PureWindowsPath('c:/Program Files/PSF') >>> p.parts ('c:\\', 'Program Files', 'PSF') (note how the drive and local root are regrouped in a single part) The parent, name, stem, and suffix properties describe different parts of a path.
02:03
Why Python? - Intro to Python 🍎📚 STEM For Others - YouTube
11:37
P&S03- Learn Stem and Leaf Plots With Python Made EASY - YouTube
Python - Stem-and-Leaf Display
02:47
Python - Stem-and-Leaf Display with stikpetP - YouTube
10:47
Matplotlib Crash Course: Python Data Visualization Course | Stem ...
My Stem Project Python Lecture 4 : If Conditions and Loops
Matplotlib
matplotlib.org › stable › api › _as_gen › matplotlib.pyplot.stem.html
matplotlib.pyplot.stem — Matplotlib 3.11.2 documentation
A stem plot draws lines perpendicular to a baseline at each location locs from the baseline to heads, and places a marker there. For vertical stem plots (the default), the locs are x positions, and the heads are y values.
PyPI
pypi.org › project › stem
stem
JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
Pythontic
pythontic.com › visualization › charts › stem plot
Stem plot using Python and Matplotlib | Pythontic.com
A stem plot separates the digits in data points to form two columns. Python Matplotlib draws a stem plot as a set of Y values plotted against common X-axis values.
Top answer 1 of 7
40
You could just .split it:
>>> Path('logs/date.log.txt').stem.split('.')[0]
'date'
os.path works just as well:
>>> os.path.basename('logs/date.log.txt').split('.')[0]
'date'
It passes all of the tests:
In [11]: all(Path(k).stem.split('.')[0] == v for k, v in {
....: 'a': 'a',
....: 'a.txt': 'a',
....: 'archive.tar.gz': 'archive',
....: 'directory/file': 'file',
....: 'd.x.y.z/f.a.b.c': 'f',
....: 'logs/date.log.txt': 'date'
....: }.items())
Out[11]: True
2 of 7
9
Why not go recursively?
from pathlib import Path
def true_stem(path):
stem = Path(path).stem
return stem if stem == path else true_stem(stem)
assert(true_stem('d.x.y.z/f.a.b.c') == 'f')
Arch Linux
archlinux.org › packages › extra › any › python-stem
Arch Linux - python-stem 1.8.3-4 (any)
View the file list for python-stem · View the soname list for python-stem · Copyright © 2002-2026 Judd Vinet, Aaron Griffin and Levente Polyák. The Arch Linux name and logo are recognized trademarks. Some rights reserved.
Matplotlib
matplotlib.org › stable › gallery › lines_bars_and_markers › stem_plot.html
Stem plot — Matplotlib 3.11.2 documentation
import matplotlib.pyplot as plt import numpy as np x = np.linspace(0.1, 2 * np.pi, 41) y = np.exp(np.sin(x)) plt.stem(x, y) plt.show()
GeeksforGeeks
geeksforgeeks.org › machine learning › python-stemming-words-with-nltk
Python | Stemming words with NLTK - GeeksforGeeks
July 11, 2025 - A stemming algorithm reduces the words “chocolates”, “chocolatey”, and “choco” to the root word, “chocolate” and “retrieval”, “retrieved”, “retrieves” reduce to the stem “retrieve”.
DataCamp
datacamp.com › tutorial › stemming-lemmatization-python
Stemming and Lemmatization in Python | DataCamp
June 1, 2026 - This tutorial covers stemming and lemmatization from a practical standpoint using the Python Natural Language ToolKit (NLTK) package.
» pip install stemgraphic
IEEE Xplore
ieeexplore.ieee.org › document › 9388001
STEM and STEAM Technologies in Problem Solving with Python | IEEE Conference Publication | IEEE Xplore
The article deals with the structure and methods of construction of the course "Problem Solving with Python" using STEM and STEAM technologies. The course is built on the principle of "visualization and problem solving head first". The techniques are offered to make the course easy to understand, including operations with NumPy arrays and slices, libraries of the Python ecosystem, domain-specific languages.
Readthedocs
pyrolite.readthedocs.io › en › develop › examples › plotting › stem.html
Stem Plots — pyrolite 0.3.8.dev8+g424552e92 documentation
ax = df.pyroplot.stem( orientation="vertical", s=12, linestyle="--", linewidth=0.5, color="k", figsize=(3, 5), ) # the yaxes can then be inverted using: ax.invert_yaxis() # and if you'd like the xaxis to be labeled at the top: ax.xaxis.set_ticks_position("top") ax.xaxis.set_label_position("top")