Intro Python: Files​

Learn how to read from and write to files — efficiently and idiomatically.

About The Course

Reading from and writing to files should be easy, given how frequently programmers need to perform these tasks. And indeed, Python makes it really easy to work with files — and in this course, you’ll see how.

This Course Will Show You How To...

_check-box

Different ways to read from text files, including iteration

_check-box

"with" — what it does, and how you should use it

_check-box

Working with CSV and JSON files

_check-box

Best practices for working with files

_check-box

Different ways to write to text files

Preview The Course

Absolute and relative paths

Using With

Print and sys.stdout

Course Contents

Course Length

6.4 Hours

Number of Lessons

52

Training Materials

7 PDFs

Coding Exercises

15

  • Intro (2 mins)
  • Files, filesystems, and file objects (6 mins)
  • Opening files (5 mins) 
  • Absolute and relative paths (8 mins)
  • Exceptions (6 mins) 
  • Reading from files (11 mins) 
  • Iterating over files (7 mins)
  • Filtering (5 mins) 
  • comprehensions (3 mins)
  • Exercises 1 (3 mins)
  • Exercises solutions 1 (8 mins) 
  • Closing files (6 mins)
  • Using “with” (7 mins)
  • Closing files in “for” loops (3 mins)
  • Exercises 2 (2 mins) 
  • Exercises 2 solutions (6 mins)
  • os.listdir and os.path.join (7 mins)
  • glob.glob (7 mins) 
  • Writing to files (13 mins)
  • Appending with “a” (4 mins)
  • Line-buffered output (4 mins)
  • Print and sys.stdout (6 mins)
  • Sys.stderr and redefining sys.stdout (5 mins)
  • “with” and multiple files (5 mins)
  • Exercises 3 (2 mins)
  • Exercises 3 solutions (6 mins)
  • Unicode and encodings (14 mins)
  • Specifying an encoding (9 mins)
  • Strings and bytestrings (9 mins)
  • Reading and writing bytes (7 mins)
  • Identifying JPEGs by their bytes (6 mins)
  • Exercises 4 (1 min)
  • Exercises 4 solutions (7 mins)
  • Moving around with “seek” and “tell” (10 mins)
  • Working with r+, w+, and a+ modes (8 mins)
  • Newlines (10 mins)
  • Sys.stdin (7 mins)
  • Os.path (6 mins)
  • StringIO (4 mins)
  • Os.walk (7 mins)
  • Exercises 5 (1 min)
  • Exercises 5 solutions (12 mins)
  • Pathlib (10 mins)
  • Pathlib and directories (7 mins)
  • Pathlib and files (7 mins)
  • Exercises 7 (1 min)
  • Exercises 7 solutions (6 mins)
  • Conclusion (2 mins)

This Course Is Perfect For...

_check-box

Experienced developers in a non-Python language who want to start using Python beyond copying from Stack Overflow and ChatGPT.

_check-box

People who have been through a basic Python course before, and want to go beyond the syntax to really understand what's going on and how to use Python effectively.

_check-box

If you have already taken my "Intro Python: Fundamentals" and "Intro Python: Functions" courses before, then this is the logical next step.

GET STARTED NOW

Monthly

Annual

Save 20%

BUY THIS COURSE

One-Time Purchase (Lifetime Access)
$ 180 One-Time
  • Read and write files — efficiently and idiomatically
  • Understand the "with" construct
  • Work with CSV and JSON formats

OR

GET A MEMBERSHIP

Access All My Training
$ 40 Per Month
  • All my Python courses
  • Monthly office hours + special events
  • Private forum

BUY THIS COURSE

One-Time Purchase (Lifetime Access)
$ 180 One-Time
  • Read and write files — efficiently and idiomatically
  • Understand the "with" construct
  • Work with CSV and JSON formats

OR

GET A MEMBERSHIP

Access All My Training
$ 400 Per Year
  • All my Python courses
  • Monthly office hours + special events
  • Private forum

100% Money Back Guarantee

I’m a one-person company dedicated to improving your career via Python and related technologies. If you haven’t gotten value from any of my courses, then just tell me — and I’ll refund your money.

Meet Your Instructor

Reuven is a full-time Python trainer. In a given year, he teaches courses at companies in the United States, Europe, Israel, India, and China — as well as to people around the world, via his online courses.

Reuven created one of the first 100 Web sites in the world just after graduating from MIT’s computer science department. He opened Lerner Consulting in 1995, and has been offering training services since 1996.

In 2020, Reuven published “Python Workout,” a collection of Python exercises with extensive explanations, published by Manning. He’s currently finishing edits on “Pandas Workout,” a similar collection of exercises using the “Pandas” library for data analytics.

Reuven’s free, weekly “Better developers” newsletter, about Python and software engineering, is read by more than 30,000 developers around the globe. His “Trainer weekly” newsletter is popular among people who give corporate training.

Reuven’s most recent venture is Bamboo Weekly: Every Wednesday, he presents a problem based on current events, using a public data set. And every Thursday, he shared detailed solutions to those problems using Pandas.

Reuven’s monthly column appeared in Linux Journal from 1996 until the magazine’s demise in 2019. He was also a panelist on both the Business of Freelancing and Freelancers Show podcasts.

Reuven has a bachelor’s degree in computer science and engineering from MIT, and a PhD in learning sciences from Northwestern University. He lives in Modi’in, Israel with his wife and three children.