← Winnitude! Search  ·  Reader Mode (229 ms)
Links: Stay in Reader Retro Site Converter Retro Mode: OFF Original Page ↗
REAL PYTHON · Real Python · 36 LINKS

Using Python's pathlib Module - Real Python

Go to the next lesson

Using Python's pathlib Module

Darren Jones 12 Lessons 49m intermediate python

Have you struggled with file path handling in Python? With the pathlib module, the struggle is now over! You no longer need to scratch your head over code like this:

Language: Python
>>> path.rsplit('\\', maxsplit=1)[0]

And you don't have to cringe at the verbosity of something like this:

Language: Python
>>> os.path.isfile(os.path.join(os.path.expanduser('~'), 'realpython.txt'))

In this video course, you'll learn how to:

  • Work with file paths in Python
  • Read and write files in new ways
  • Manipulate paths and the underlying file system
  • List files and iterate over them

Using the pathlib module, the two examples above can be rewritten using elegant, readable, and Pythonic code:

Language: Python
>>> path.parent
>>> (pathlib.Path.home() / 'realpython.txt').is_file()

That's what you'll master in this video course!

What's Included:

  • 12 Lessons
  • Video Subtitles and Full Transcripts
  • Translated Subtitles in 8 Languages
  • 1 Downloadable Resource
  • Accompanying Text-Based Tutorial
  • 3 Hands-On Coding Exercises
  • Q&A With Python Experts: Ask a Question
  • Certificate of Completion

Downloadable Resources:

Related Learning Paths:

Start Now

Understanding Python File Paths

2 Lessons 3m

  1. 1. Using Python's pathlib Module (Overview) 01:31
  2. 2. Understanding Python File Paths 02:10

Working With Paths

4 Lessons 17m

  1. 1. Working With Paths 03:49
  2. 2. Reading and Writing Files 03:01
  3. 3. Exercise: Read a File With Pathlib 08:00
  4. 4. Moving and Deleting Files 02:23

Diving Deeper Into Paths

6 Lessons 28m

  1. 1. Picking Out Components of a Path 01:37
  2. 2. Exercise: Rename Path Components 08:00
  3. 3. Exploring the Finer Details of Path 05:19
  4. 4. Trying Out pathlib in Action 05:02
  5. 5. Exercise: Count File Types in a Directory 08:00
  6. 6. Using Python's pathlib Module (Summary) 00:54
Start Now

About Darren Jones

With 20 years as a teacher of music technology, Darren is keen to bring his skills to the Python table.

» More about Darren

Each tutorial at Real Python is created by a team of developers so that it meets our high quality standards. The team members who worked on this tutorial are:

Christopher

Kate

Tappan

Geir Arne

Dan

Joanna

Aldren

Martin

Bartosz

Philipp

Brenda

Related Courses:

Context Managers and Using Python's with Statement

Working With JSON in Python

← Browse All Courses