From the course: Learning the Python 3 Standard Library

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Files and file writing

Files and file writing

- [Instructor] Before we start messing with files in Python, we actually need to create a file. And so here, I'm going to go up to File, New, just creating a new file in this current directory or the Python file I'm running is, and I'm just going to call this new file scores.txt. And here it is, it's in that same directory and were just going to keep this file blank. We're going to save it. And we're actually going to mess with it inside of our Python code. To get access to this file, we'll actually create a variable called myFile in here, and then we'll go open scores.txt. So the name of the file we want to open and then w for the mode that we want to open it in, and here w stands for write. If we put r here, it would be read; r+ plus would be read and write; a for append, but we're going to keep it w for now. Once we open this file, then it's going to be saved inside of this myFile variable, and that's what we'll use…

Contents