Skip to content

Instantly share code, notes, and snippets.

@dfur
dfur / Python pathlib guide.md
Last active November 19, 2022 06:33
A brief tour of all the properties and methods in the python standard library 'pathlib' module which provides easy, object oriented file handling in modern python.

Easy object-oriented file handling in modern python

A brief tour of all the properties and methods in the pathlib module.

The pathlib module is part of the Python stardard library (as of v. 3.4) and can be used can do file handling tasks previously done by multiple libraries. Instead of using mere strings to represent filepaths, pathlib uses objects that have many useful properties and methods.

For example, pathlib can replace (amongst others):

os - .rename(), .sep(), .walk(), .chmod(), .mkdir(), .stat()
os.path - .join(), .split(), .exists(), .basename()