Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Practical Recipes for Working With Files in Python (Summary)

You now know how to use Python to perform the most common operations on files and groups of files. You’ve learned about the different built-in modules used to read, find, and manipulate them.

You’re now equipped to use Python to:

  • Get directory contents and file properties
  • Create directories and directory trees
  • Find patterns in filenames
  • Create temporary files and directories
  • Move, rename, copy, and delete files or directories
  • Read and extract data from different types of archives
  • Read multiple files simultaneously using fileinput

Sample Directories (.zip)

51.6 KB

Course Slides (.pdf)

333.6 KB

Robb Glietz on Aug. 4, 2020

Great video learned a ton about how files work in Python. Thank you.

Liam Pulsifer RP Team on Aug. 5, 2020

Glad to hear it @Robb Glietz! I hope you get a chance to put some of this to use in your own projects :)

Robert T Paulsen on Aug. 7, 2020

Nice job - I learned some interesting things. The zip section did get a bit cluttered as you noted.

Hilman on Aug. 9, 2020

Beautiful, easy-to-understand series. Thank you.

agerbes on Aug. 9, 2020

Awesome Tutorial. Good Job!

gabrielmachac on Aug. 14, 2020

Thank you for this great tutorial.

Ranjit Shrivastva on Aug. 16, 2020

Great stuff from handling of files in python. got something new which can be used in my current project. great job. Thanks for this great tutorial.

johnnypham on Aug. 20, 2020

Question about slow execution time shutil.make_archive.

shutil.make_archive took several minutes to get back to my Linux prompt. Why did that happen? How can we improve the execution time?

Here is my code:

import os
import shutil
import zipfile
shutil.make_archive('', 'zip')

Thanks, Johnny P.

Liam Pulsifer RP Team on Aug. 23, 2020

Thanks for the kind comments, all!

@johnnypham, interesting issue you’re having! If you don’t mind my asking, what directory are you running this script from? I notice you haven’t specified a root directory from which to create the archive, so if you ran this from your top-level directory on your machine, it would be zipping all the files on your server, which would take a while. It would probably be safer as a test script to specify the root directory explicitly. You could also add a print statement to print out the current working directory using the os module so that you can be a little more sure what’s going on.

tobenary on Aug. 30, 2020


jamesbrown68 on Aug. 30, 2020

Good course, Liam. Thanks for the time and effort.

Liam Pulsifer RP Team on Sept. 8, 2020

Thanks for the comment @jamesbrown68! Glad you enjoyed the course.

Doug Ouverson on April 21, 2021

Thanks Liam for a job well done! I benefited greatly from the information.

aniketbarphe on Sept. 26, 2021

Great One! Thank You!

Robert T on Sept. 30, 2021

Great course, Liam, I learned a lot and this will help me in the future!

jillwellman on May 4, 2022

Excellent course. Complete. Efficiently presented. I love having the video to go through for an overview. Will return and work through the examples semi-independently to get the skills I need right now. Thank you for your work!

Become a Member to join the conversation.