Python for Absolute Beginners Transcripts
Chapter: Reading and writing files in Python
Lecture: Practice exercises
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Well that's enough reading and writing files for me.
0:03
It's time for you to read and write to some files yourself.
0:06
So you're going to do some similar things
0:08
that we've done here, work with JSON files
0:09
work with lines of texts and plain text files.
0:12
Let's go see what I got on deck for you.
0:15
Over here in chapter nine working with files
0:17
you've got the standard introduction
0:19
threw in a few concepts for you, determining the full
0:21
path of a file using os.path, reading a file
0:24
using with open file name r, write in to a file
0:29
make it a w, working with a JSON, import this
0:34
loading from and writing to various files
0:36
and finally, the exercises that you're going to do
0:39
are going to be going back to the games that we created.
0:42
So, the Tic Tac Toe game from back in CH08
0:46
the one about problem solving at least
0:47
whatever number that turns out to be
0:49
at the end of this course, and work with that.
0:51
If you happen to have gotten all the way
0:52
through the previous chapters exercises
0:55
and you did build Connect Four, that one's yours.
0:58
Go ahead and use that instead.
0:59
The idea, we'll work with either of them.
1:01
What we are going to do is just create a leaderboard.
1:03
Use JSON format if you like.
1:05
That works out really easy so that's what we did.
1:07
So a leaderboard, create that, and update it
1:09
as you win and play.
1:11
Then add a running log file.
1:12
This can just be appending to a text file
1:14
nothing about it fancy, logging frameworks
1:16
and just do that.
1:17
That will help you practice appending to text files.
1:19
That'll be great.
1:20
If you want to, and you get to the end
1:23
and you want to try it out, you could use Logbook.
1:25
It's going to cover some of the topics we cover
1:26
in the external libraries package as well.
1:30
So, you don't have to do it now
1:31
but if you're feeling ambitious
1:33
feel free to go though their quick start
1:35
and give it a shot.
1:36
If it doesn't work, don't worry.
1:37
We'll talk about more of it for the next chapter.
1:39
But this is a really cool library
1:41
that helps you do logging the right way
1:43
and it's what we use
1:44
and it's been working great for years.
1:45
Alright, get out there and have some fun
1:48
adding file IL to the games that you built.