Reading and Writing Files

Input and Output for the Win3 H

Just you? Training a whole team? There's an ITProTV plan that fits.

Start Training Today
  • Reading and Writing Files
    • Overview
    • Open and Close a File
    • Read a File
    • Write a File
    • Use a Context Manager
    • Loop Through Multiple Files
    • Loop Through a File: fileinput
    • Loop Through Multiple Files: fileinput


3 M

itprotv course thumbnailitprotv course thumbnailitprotv course thumbnail
  • Episode Description
  • Transcript

A staple of programming is manipulating data, particularly data saved in files. In this series, we will explore the facilities that Python provides for reading and writing files. If you want to get going with file-based fun, then we will see you there.

[MUSIC] >> Hello and thank you for watching DevPro.TV. We're gonna be talking about reading and writing files in Python with Justin Dennison. Now Justin, can you tell us about what this course offers or what it will offer to people? >> So this course is meant to take this Python knowledge that we've been slowly gathering. But right now, we don't really have any way to do anything other than type directly inside of the code. Well, that's not a sustainable process. So the ultimate goal of this course is to explore how we can open and close files. Read from them, write to them. And well, use that to solve some interesting problems. But I will highlight kind of these edge cases like don't forget to close your file. Don't forget to open it in the right mode and that is also a focus of this course. >> So who is this show targeted towards? >> So this is someone who's just getting started in Python or even programming. Maybe you've programmed a little bit or you never have before, a little bit of Python. You can probably pick this up fairly easy. I would recommend looking at some of our previous, getting up to speed in Python courses that'll make this course a little easier. But anybody can jump in just if you have a very particular problem that you want to solve and you're like well, I'll try it with Python. Let's see how it works, definitely come on in. Now if you've had programming experience, you may be better served moving forward along. So this is meant to help those who are just getting started kind of keep moving forward. >> Is this is a certification based program? >> This is not certification based. A lot of times in programming languages, it's hard to certify. Because the language or what is acceptable by the community, or how things work can change very rapidly in comparison to hardware based technologies. So certification doesn't exist for this particular thing. This is more of a let's power up our skills and of course, in conjunction with other courses. >> Could you tell us a little bit more on what topics are gonna be covered in reading and writing files? >> So reading and writing files, specifically. We're going to lean how to open a file. We're gonna learn how to close a file and what the implications of, if I open a file and don't close it. I'm also going to learn how to read from a file. But not only, you're like you just read from a file. You open it up. Well, we actually cover that we can read in a variety of manners. We can read line by line. We can read all the lines. We can read everything in as a string. Correspondingly, we can write to a file. But writing has some other edge cases like well, if I write to a file, do I get to keep the stuff in the file? Well, it actually depends. So we're gonna cover the mode of writing. Do I append or do I write over? Can I read if a file is write? Well, you have to be careful. So we're gonna cover that, as well. And then furthermore, we're going to start bringing in another part of the Python standard library to see how to read multiple files or to some extent how to make a reusable utility. So I think that gives a pretty good overview of all of our topics. >> Thank you, Justin. If reading and writing files seems like something you're interested in and you wanna become one step closer to being a Python pro, then be sure to check out all the episodes that Justin to offer in this course, in our course library. Thanks for watching. [MUSIC]