 So today what we're talking about is file handling, especially inside of our Python programs. The reason why is because when we think about, say for example, why this is important, we have to remember that memory, when we think about RAM specifically, it is known as being volatile, which means that as soon as it loses power, it loses all of its information. And that's actually one of the reasons why if you think about your program, right, your program is getting loaded into RAM memory. And so any data that your variables are storing, when you close out of your program, that needs to get removed out of RAM so it can work off of other things. But if you think about it, that's not how a lot of our world works, you know, I want pictures, I want textiles, I want papers I have to write for classes and whatnot. Here's another example, right. I have video games that I want to play, and I want to store. So in this case, perfect example, you know, you're in a post apocalyptic zombie world instead of virus world. And so what you're doing is I need to store my progress, well, that needs to go somewhere and it needs to stay. That way I can close out of the game and I can come back to this at another time. One has that exact same process going on there. And to reference those specific files, we work off of two types of references, absolute and relative file references. So say for example, I'm going to be working off of this directory inside of my computer. It's on my desktop, it's inside of a folder called CSE 111. Now I can't just magically take my temp.py and have it appear wherever I want. So say for example, you know, we're not going to be working too much on the command prompt, but I have a temp file, I've written it, I want it to do something. If I've tried to come in here right now and say, oh, let's run, say for example, that temp file, well, Python is going to error, it doesn't know where that is, it doesn't see it. That's because specifically I'm not in the same directory as my file. Now that's where something known as an absolute file path comes into play. So the entire idea is, I know where that file is. It is literally inside of my desktop, inside of a folder, there's the Python file. So what I can do is I can give the full directory of it. Now this is a lot of typing, yes. So desktops, CSE 111, temp.py. Now since I've given it the entire address of where it is in my computer, it doesn't do anything. The big thing here is it didn't error. But as you can see, that's a lot to be working off of. What we can also do is we can do relative file referencing. So I actually was just doing that up here. The entire reason why Python temp error is because it said, well, you're in a directory. I'm currently in my Atom directory. So what if I went into that folder? Okay, well, I know that there is a temp file in there, right? I can list that right here. I see it. So now a relative file reference is this idea that I look with respect to where I currently am. So I am currently in this directory. And so I can say, for example, come in, same kind of thing, Python temp. And now I should not get an error because, again, there's my temp.py file, exactly. So as you can see, I've got a hello world, or sorry, a hello.txt. It has hello world inside of it. The same kind of concept comes in. What if I wanted to write programs that could access what was inside of that particular file? How could I do that? So there are two different ways. I could work off of the absolute reference to start. And so I'll go ahead and do that. I'll call a variable filename, c slash users slash atom slash desktop slash csc111 slash hello.txt. Now one thing you might be asking yourself specifically if you're on a Windows machine is why is it that, you know, maybe you can see this, why is it there are slashes like this going, well, going that way on the screen, but I typed it this way. And specifically the same kind of thing going on here. You can see that these slashes are, again, going like that. Well, reason why is because, again, if we go back in time for just a second, that's how we reference special characters, right? That forward slash in, that backward slash, that one, that one, that one. This slash is how we were using special characters. So like slash in for new lines and slash t for tabspaces and if I wanted to show Unicode characters. So just having it wildly available inside of a file path, that's not something that Python is going to be able to handle. So inside of it, it says, well, okay, we're just going to make a rule, you know, for file paths, we are working off of this style slash. Okay. So again, this is an absolute file path reference. Now what I can do with this is I can use a new function inside of Python. It's called open. So I like to always name my files when I'm accessing them, phi, because file is typically reserved. So phi equals open filing. Now the open command also has a another parameter that it's expecting. This parameter is going to be one of three letters, W, R or A. Now we're going to talk about W and A in a little bit, but specifically because we want to see what's inside of hello.txt, we want to work off of the R. R stands for read. So with that in mind, just to show this off, if I hit run, excellent. That's a great confirmation that I am accessing my file. It is getting opened. So those things are happening and we can even confirm that by typing in our phi. You see some crazy nonsense going on right here, but that's perfectly fine. It just means I have my file is ready to be read now specifically with that idea of read. If I want to read my file, I have to sort of treat this phi variable as an object. That's exactly what this giant block of text is really telling me. I'm dealing with an object in Python. How we've dealt with objects in the past strings lists. So phi.read. Now, phi.read is basically going to say whatever is inside of that file, read it in. Now, if I just do read, I'll actually just show you, I don't see anything because, again, think about that just like pretty much most of Python. I'm not saving it or doing anything to that read. I literally just read the file and Python says, okay, you have the contents and didn't do anything to them. So as a rule of thumb, I always like to use the term contents here, just the contents of the file. It's typically my go to word for this. Now, last little thing we'll do is say, well, let's print those contents, no contents. And as you can see, I run through this. I opened up the file path, saw it, read it, contents, hello world.