#Pathlib
With both arguments, a mkdir will make parent directories as needed and not complain if the directory already exists.

An exception will still be raised for other issues (like if there's a file at that path).
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 8, 2026 at 5:26 AM
Still building file paths by gluing strings together?

Python's pathlib gives you Path objects that work the same on every OS. The tutorial has ready examples, like finding the file you changed last.

realpython.com/python-pathl...
Python's pathlib Module: Taming the File System – Real Python
Handle file and folder paths the modern way with Python pathlib, a built-in module whose semantics work the same on every OS.
realpython.com
November 7, 2026 at 8:30 PM
Pythonのpathlibで拡張子を調べる:.tar.gzと隠しファイルで起きる意外な違い

Python pathlibのsuffixとsuffixesで.tar.gzや隠しファイルを分類。名前と実体の違いを解説。
Pythonのpathlibで拡張子を調べる:.tar.gzと隠しファイルで起きる意外な違い
Python pathlibのsuffixとsuffixesで.tar.gzや隠しファイルを分類。名前と実体の違いを解説。
papanda925.com
November 8, 2026 at 11:05 PM
Python pathlibで.tar.gzを判定する:suffixとsuffixesの違い

Python pathlibのsuffixとsuffixesを架空のファイル名で比較。tar.gzの判定、境界条件、拡張子と実体の違いを解説。
Python pathlibで.tar.gzを判定する:suffixとsuffixesの違い
Python pathlibのsuffixとsuffixesを架空のファイル名で比較。tar.gzの判定、境界条件、拡張子と実体の違いを解説。
papanda925.com
November 8, 2026 at 3:05 AM
Instanziieren Sie eine reine pathlib‑Klasse, wenn Sie Pfad‑Operationen ohne Dateisystem‑Interaktion benötigen.
https://docs.python.org/3/library/pathlib.html
November 6, 2026 at 10:44 AM
Still importing os, glob and shutil just to move a few files?

pathlib does all of it with one Path object, the same way on every OS.

The tutorial ends with real examples, like finding the file that changed last.

realpython.com/python-pathl...
Python's pathlib Module: Taming the File System – Real Python
Handle file and folder paths the modern way with Python pathlib, a built-in module whose semantics work the same on every OS.
realpython.com
November 3, 2026 at 9:30 PM
oh! Been working with my scripts and I've been using

__package__ = "your_package"

pathlib can also be imported with

__package__ = __package__ or Path(__file__).resolve().parent.name

make sure parentdir is on sys.path nested pkgs must be full dotted name

this ONLY works on 3.14 or older though
November 3, 2026 at 2:54 PM
Stop manually parsing logs. Python’s `re` and `pandas` libraries can automate your SIEM alerts in minutes, not hours.

Pro-tip: Use `pathlib` for cross-platform file handling in your IR scripts. Stop wasting time on CLI boilerplate.

#Python #SecOps #InfoSec
November 3, 2026 at 11:14 PM
full string parse

from pathlib import Path
__path__ = [str(Path(__file__).resolve().parent)]
November 3, 2026 at 2:55 PM
python3 - <<'EOF'
import json,re,sqlite3,pathlib
exec("def J(x):\n try: return json.loads(x)\n except Exception: return None")
B=pathlib.Path.home()/'Library/Application Support/Wispr Flow'
O=pathlib.Path.home()/'Desktop/wispr-export'
O.mkdir(parents=True,exist_ok=True)
November 2, 2026 at 7:54 PM
maybe I'll spelunk in `pathlib` and see if there's a sensible way to make the function variadic like this, and shove an `any()` in there
October 30, 2026 at 7:34 PM
I tend to use "from" imports most because I prefer short and descriptive variable names:

from dataclasses import dataclass
from pathlib import Path

But if there's a name like choice that isn't as clear as random.choice, then I'd recommend importing the whole module for the more descriptive name.
October 31, 2026 at 6:04 PM
okay right, refreshing my memory about how `pathlib` is implemented, I had forgotten about the "selector" abstraction, which does complicate matters.

`Path.glob(pattern)` ends up calling `_make_selector(tuple(pattern_parts), self._flavour)` and then yielding from `selector.select_from(self)` […]
Original post on hachyderm.io
hachyderm.io
October 30, 2026 at 9:47 PM
I've read the impl of `pathlib` before but there's a lot of fuzz to it, so the details never stick in my mind beyond knowing that `Path` itself is a façade and that there's more machinery in there than you might think to handle all the variation across filesystems in maintainable/reusable ways
October 30, 2026 at 7:35 PM
Linh Fish Dev Podcast #17: Python thay os.path bằng pathlib — đọc, ghi và duyệt file gọn hơn trong 5 phút

Tập 17: Python thay os.path bằng pathlib — đọc, ghi và duyệt file gọn hơn trong 5 phút. Với os.path, đường dẫn chỉ là chuỗi ký tự: bạn phải nhớ đúng thứ tự đối số của join, tự lo dấu phân…
Linh Fish Dev Podcast #17: Python thay os.path bằng pathlib — đọc, ghi và duyệt file gọn hơn trong 5 phút
Tập 17: Python thay os.path bằng pathlib — đọc, ghi và duyệt file gọn hơn trong 5 phút. Với os.path, đường dẫn chỉ là chuỗi ký tự: bạn phải nhớ đúng thứ tự đối số của join, tự lo dấu phân cách, và một thao tác đơn giản cũng cần kết hợp nhiều hàm rời rạc, lại dễ lệch giữa Windows và Linux.
linhfish.dev
October 29, 2026 at 1:48 PM
Python: thay os.path bằng pathlib — đọc, ghi và duyệt file gọn hơn trong 5 phút

Nếu bạn vẫn nối đường dẫn bằng os.path.join và kiểm tra file bằng os.path.exists, hãy thử pathlib.Path. Nó biến đường dẫn thành một đối tượng có sẵn phương thức đọc, ghi, tạo thư mục và duyệt file, nên code ngắn hơn,…
Python: thay os.path bằng pathlib — đọc, ghi và duyệt file gọn hơn trong 5 phút
Nếu bạn vẫn nối đường dẫn bằng os.path.join và kiểm tra file bằng os.path.exists, hãy thử pathlib.Path. Nó biến đường dẫn thành một đối tượng có sẵn phương thức đọc, ghi, tạo thư mục và duyệt file, nên code ngắn hơn, đọc xuôi hơn và ít lỗi sai dấu phân cách giữa Windows với Linux. Bài này áp dụng khi bạn viết script xử lý file, tool nội bộ hoặc bất kỳ đoạn code Python nào phải chạm tới hệ thống file.
linhfish.dev
October 29, 2026 at 9:08 AM
Python's pathlib Module: Taming the File System
tech_blogs_real_python

#Python
Python's pathlib Module: Taming the File System
Handle file and folder paths the modern way with Python pathlib, a built-in module whose semantics work the same on every OS.
realpython.com
October 26, 2026 at 12:30 PM
🐍📰 Python&#x27;s pathlib Module: Taming the File System
realpython.com
October 25, 2026 at 2:21 PM
I just scored 88% on Real Python's "Python's pathlib Module: Taming the File System" quiz. What's your score? realpython.com/quizzes/pyth...
My Quiz Score – Real Python
I just scored 88% on Real Python's "Python's pathlib Module: Taming the File System" quiz. What's your score?
realpython.com
October 25, 2026 at 6:19 PM
I love pathlib to work with files/path . One thing missing is executing and piping commands easily. What would you use?
October 24, 2026 at 12:30 PM
New logo for my pathlib replacement lib! Trying to recreate this ChatGPT image gen
October 18, 2026 at 6:01 PM
You can find a printable version of this cheat sheet (both US Letter and A4) at pym.dev/cheat-sheets

The printable version shows more features for each version and a support timeline.

All my cheat sheets are free with a (free) Python Morsels account.
Printable Python Cheat Sheets
Printable one-page Python cheat sheets from Python Morsels: built-in functions, string methods, f-strings, comprehensions, asterisks, pathlib, date formats, regular expressions, time complexity, the…
pym.dev
October 14, 2026 at 10:45 PM
Python startup times just got faster.

In 3.15, you can use the keyword `lazy` to make a lazy import (`math` and `Path` below).

Lazily imported modules are only loaded

WHEN they're used, and

IF they're used.

Use them to defer loading of modules that may not be required.
October 14, 2026 at 1:02 PM
Today's pet peeve: Python pathlib understands that filenames may have multiple suffixes:

>>> Path("foo.tar.xz").suffixes
['.tar', '.xz']

But there is no corresponding "just the real actual stem", .stem includes all but the final suffix:

>>> Path("foo.tar.xz").stem
'foo.tar'

Similarly […]
Original post on social.coop
social.coop
October 11, 2026 at 2:39 AM
Stop manually parsing logs. Python’s `re` and `pandas` libraries can automate threat hunting in seconds, not hours.

Pro-tip: Use `pathlib` for cross-platform log ingestion to avoid headache-inducing syntax errors. Code smarter, defend faster. 🐍

#Python #InfoSec
October 9, 2026 at 5:43 PM