0Pricing
Python Academy · Lesson

The Path Object

Build paths the modern way.

Modern Paths with pathlib

The pathlib module represents filesystem paths as objects instead of plain strings. A Path object knows how to join, split, and inspect itself, replacing many scattered os.path functions.

Creating a Path

Import Path and construct one from a string. Printing it shows the path text.

from pathlib import Path

p = Path('folder/file.txt')
print(p)

All lessons in this course

  1. The Path Object
  2. Reading and Writing Files
  3. Globbing and Iterating
  4. Path Manipulation
← Back to Python Academy