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

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds 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 the default subtitles language 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 see our video player troubleshooting guide to resolve the issue.

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

Download

Sample Directories (.zip)

51.6 KB

Download

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:

#!/usr/local/bin/python3.8
import os
import shutil
import zipfile
shutil.make_archive('made_with_shutil.zip', '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

wow!

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.

Become a Member to join the conversation.