Using Python's pathlib Module - Real Python
Using Python's pathlib Module
Darren Jones 12 Lessons 49m intermediate pythonHave 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:
>>> 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:
>>> 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 NowUnderstanding Python File Paths
2 Lessons 3m
Working With Paths
4 Lessons 17m
- 1. Working With Paths 03:49
- 2. Reading and Writing Files 03:01
- 3. Exercise: Read a File With Pathlib 08:00
- 4. Moving and Deleting Files 02:23
Diving Deeper Into Paths
6 Lessons 28m
- 1. Picking Out Components of a Path 01:37
- 2. Exercise: Rename Path Components 08:00
- 3. Exploring the Finer Details of Path 05:19
- 4. Trying Out pathlib in Action 05:02
- 5. Exercise: Count File Types in a Directory 08:00
- 6. Using Python's pathlib Module (Summary) 00:54
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 DarrenEach 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