Python Quest

Track 8 · Lesson 3 of 11

Paths and folders with pathlib

Build file paths with pathlib.Path, check what exists, list files with glob, create folders and read or write text in one call.

About 35 minBeginner4 exercises

You will be able to

  • Build paths with Path and the / operator instead of gluing strings together
  • Inspect a path's name, stem, suffix and parent, and check whether it exists
  • List the files in a folder with iterdir() and glob() in a predictable order
  • Create nested folders with mkdir(parents=True, exist_ok=True) and use read_text()/write_text()

Included with a Formula Quest membership

It has 4 graded exercises with feedback, hints and solutions. Python Quest is included in Formula Quest memberships that cover Python; membership and billing are managed on Formula Quest.

View Formula Quest memberships

Tracks 1 and 2, the first lesson of every track, the playground and the dataset library are free.