#pathlib
I just published a pathlib cheat sheet & sales pitch combination post that I'd been drafting for months. ✨

If you've been looking for a post to link your pathlib-curious/confused coworkers to, I'm hoping this will help. #Python

pym.dev/pathlib-module
Python's pathlib module
Python's pathlib module is the tool to use for working with file paths. See pathlib quick reference tables and examples.
pym.dev
November 18, 2024 at 4:44 PM
In Python, instead of this:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

I prefer this:

BASE_DIR = pathlib.Path(__file__).resolve().parent.parent

For more on the magic of #Python's #pathlib, check out the article I published last week:
Python's pathlib module
Python's pathlib module is the tool to use for working with file paths. See pathlib quick reference tables and examples.
pym.dev
November 27, 2024 at 2:00 AM
I've updated my new #pathlib article with additional examples, improved wording, and more links to documentation. ✨

One nice thing about finally publishing in text form: #Python folks happily provide (frequently) constructive feedback so I can immediately iterate. 💗

pym.dev/pathlib-module
Python's pathlib module
Python's pathlib module is the tool to use for working with file paths. See pathlib quick reference tables and examples.
pym.dev
November 20, 2024 at 3:08 AM
Also, to change the non-extension part of a filename, you can use with_stem:

>>> old_path.with_stem("README")
PosixPath('uvrs/README.rst')

And to replace the whole name, there's with_name:

>>> old_path.with_name("Read Me.txt")
PosixPath('uvrs/Read Me.txt')
Python's pathlib module
Python's pathlib module is the tool to use for working with file paths. See pathlib quick reference tables and examples.
pym.dev
September 24, 2026 at 5:02 PM
10/ `with open(path) as f:` and `os.path` do a superset of what `pathlib` does, so you can replace all uses of pathlib with context managers and low-level operations.

The entire Python tutorial ecosystem is ahead of the curve on this one
April 3, 2025 at 2:25 AM
Python Tip #267 (of 365):

Change file extensions with with_suffix. 🧵

A ".rst" file path that needs to turn into a ".md" file path:

>>> from pathlib import Path
>>> old_path = Path("uvrs/readme.rst")
>>> old_path.with_suffix(".md")
PosixPath('uvrs/readme.md')

#Python #DailyPythonTip
September 24, 2026 at 5:02 PM
Stop manually parsing logs. Python’s `re` and `pandas` libraries can automate your SIEM alerts in minutes.

Pro-tip: Use `pathlib` for cross-platform file handling in your IR scripts. Stop reinventing the wheel! 🐍🛡️

#PythonSecurity #InfoSec #Automation
September 22, 2026 at 3:18 PM
If you need a os/os.path/glob to pathlib conversion cheat sheet, see pym.dev/pathlib-modu...

If you just want help adopting pathlib in general, use this cheat sheet instead:
pym.dev/pathlib-modu...

This week's tips are all about pathlib patterns & anti-patterns.
Python's pathlib module
Python's pathlib module is the tool to use for working with file paths. See pathlib quick reference tables and examples.
pym.dev
April 6, 2026 at 6:04 PM
Working with file paths in Python? (splitting, joining, navigating, etc.)

Check out #Python's pathlib module.

It's great for splitting/joining paths, finding files by filename patterns, renaming files, and more.

pym.dev/pathlib-module
July 1, 2025 at 6:04 PM
Whenever a new python article uses `with open(path) as f` instead of pathlib I die a little inside
December 6, 2024 at 7:57 PM
pathlib! It's my favorite module. :)
November 30, 2024 at 11:05 AM
subprocesslib: Like `pathlib` for the `subprocess` Module #python
subprocesslib: Like `pathlib` for the `subprocess` Module #python
pypi.org
October 16, 2025 at 3:00 AM
Stop manually parsing logs! 🛑 Python’s `re` module and `pandas` can turn hours of manual triage into seconds of automated insight.

Pro-tip: Use `pathlib` for cross-platform file handling in your IR scripts. Don't work harder, work smarter. 🐍

#InfoSec #Python
September 22, 2026 at 6:12 PM
its a shame Rust didnt copy Python's pathlib interface for paths

the Pure / Concrete split is quite useful, and std already implements most/all of it but you just don't get access to it
pathlib — Object-oriented filesystem paths
Source code: Lib/pathlib/ This module offers classes representing filesystem paths with semantics appropriate for different operating systems. Path classes are divided between pure paths, which pro...
docs.python.org
June 7, 2025 at 8:07 AM
LWN covered my talk on pathlib from #PyConUS!

If you're using #Python and not using the pathlib module, check it out. I think that it's one of the most underused modules in the Python standard library.
Representing Python paths using pathlib
At the outset of his PyCon US 2026 talk, Trey Hunner said that his goal was for attendees to st [...]
lwn.net
August 21, 2026 at 5:31 PM
Python's `pathlib` Module ##python
Python's `pathlib` Module #python
Python's `pathlib` module is the tool to use for working with file paths. This post contains `pathlib` quick reference tables and examples.
www.pythonmorsels.com
December 10, 2024 at 5:00 PM
i have 169 downloads and only 1 of those told me it instantly crashes specifically on windows

cool story: renpy hard rejects paths containing backslashes, presumably so windows devs don't make stuff that needlessly fails on unix. But i used pathlib, which produces the native separator,
March 1, 2026 at 5:35 PM
lwn.net/Articles/108...
Path().path().le.join()
Representing Python paths using pathlib
At the outset of his PyCon US 2026 talk, Trey Hunner said that his goal was for attendees to st [...]
lwn.net
August 31, 2026 at 8:24 AM
Rust: Use ? operator, clippy, parameterized SQL, avoid .unwrap()
Python: Type hints, proper exceptions, pathlib, context managers
JavaScript/TypeScript: const/let, async/await, strict mode, input validation
Go: Check errors, use context.Context, defer for cleanup
December 28, 2025 at 4:05 AM
Stop manually parsing logs. Python’s `re` and `pandas` libraries can turn hours of manual grep-ing into seconds of automated analysis.

Pro-tip: Use `pathlib` for cross-platform file handling in your scripts to avoid headaches. 🐍

#InfoSec #Python #Automation
June 1, 2026 at 9:49 PM
❓🐍 Quiz: Python's pathlib Module: Taming the File System Quiz realpython.com/quizzes/pyth...
Python's pathlib Module: Taming the File System Quiz – Real Python
Revisit Python's pathlib module for handling file and folder paths consistently across operating systems. Write modern, object-oriented code.
realpython.com
February 10, 2026 at 3:12 PM
Someone (@yikestra.bsky.social) published a C library for filesystem paths with an API inspired by Python's pathlib (which I originally designed).

C++ has its own entirely different thing in std::filesystem::path.

github.com/netanel-habe...
GitHub - netanel-haber/snakepath: C99 STB style ~port of Python's standard pathlib module. Written with Claude Opus 4.5. Use at your own peril.
C99 STB style ~port of Python's standard pathlib module. Written with Claude Opus 4.5. Use at your own peril. - netanel-haber/snakepath
github.com
February 3, 2026 at 9:16 PM
Not convinced that pathlib is better than os.path and friends?

Well, unlike with strings:

1. It's hard to get yourself into trouble with pathlib.Path
2. When I see a pathlib.Path object, I know we're representing a path

I have a whole talk that might help convince you: trey.io/pathlib-talk
pathlib: Why and How to Use It
Hello! This page includes resources related to my PyBeach 2025 talk, pathlib.Path: Why and how to use it.
trey.io
April 6, 2026 at 6:04 PM
I've shipped a new script to help developers refresh their knowledge of modern Python 3.x features. It goes over type hints, f-strings, pathlib, and dataclasses, and includes a timing decorator for performance benchmarking.
https://itsevilduck.gumroad.com/l/molovi
itsevilduck.gumroad.com
September 23, 2026 at 5:32 AM