Python for Absolute Beginners Transcripts
Chapter: Using external Python packages
Lecture: 06-demo-adding-color-output

Login or purchase this course to watch this video and the rest of the course contents.
0:00 It's time to start using our Colorama.
0:02 Lets go and run this really quick.
0:03 Here you can see we've got rock, paper, scissors version
0:05 here's the header.
0:07 Maybe we want the header to be like a cool pink
0:10 or something like that.
0:11 And yet here it's just gray.
0:13 Maybe we also want to ensure
0:15 that the background or the default color is white.
0:19 For example, if I come over to my prompts
0:21 my terminal here
0:22 you can see that my normal colors are yellow.
0:26 And if I were to type python3
0:27 everything's yellow.
0:29 So for example, if I run this program
0:32 I copy this from there.
0:33 I'm going to make sure I use the Python
0:35 from that virtual environment to run this file.
0:37 Everything is now yellow.
0:39 It'd be nice to have a baseline color
0:41 for what we're doing here.
0:42 So what we can do in the beginning
0:44 is we can just start, right at the top of the file.
0:46 We can just print out some kind of text or something
0:49 using Colorama to make it that color.
0:51 So the way we do it is say colorama.
0:53 or dot, and then whatever color we want.
0:56 Let's go with white.
0:58 Now if I do this over here and run it
1:01 see everything's yellow.
1:02 But as soon as I run it it's turned everything white.
1:04 And as we work with it, it's just going to stay white.
1:06 For now, okay?
1:08 The program exits then it resets.
1:09 So this kind of does a baseline color for us
1:13 and what else do we want to do?
1:15 Let's go over here, I'm going to copy this.
1:16 I'm going to use it a lot.
1:18 I said we want to have the header have a color, right?
1:20 Let's go over here and say print or dot.
1:24 What do we want here?
1:25 Magenta, maybe?
1:27 Magenta's going to be good enough.
1:28 Now we can do it like this.
1:30 We can come down here and say that plus text
1:33 but this is so big
1:35 I'm just going to put it like this.
1:36 And we want all the stuff to be here.
1:38 And then we got to put it back, colorama.Fore.WHITE.
1:43 Okay, well one thing that we're doing a lot of
1:45 is saying colorama.Fore.that.
1:47 Now here, normally I like this format.
1:50 I like this format because it's really clear
1:52 where all this comes from.
1:53 But we're going to be combine it with a lot of text
1:55 so we can do it, import a different way.
1:58 Let's roll this back a little bit.
1:59 Notice there's an error.
2:01 We come over here and say, From colorama import,
2:05 the stuff that's in there
2:06 which is all those things.
2:08 And just say for, that arrow goes away.
2:10 If you don't type this by the way
2:12 PyCharm knows that you should have typed it
2:14 so we go over here and we can hit Alt + Enter
2:16 and it says, Do you want to import this?
2:18 You want colorama.Fore?
2:19 Yes I do, and it'll just write that line
2:21 as if we had done it up there.
2:23 All right, so that's a lot of talking.
2:25 Let's see what we're getting here.
2:28 this up and try it again.
2:31 Check it out.
2:32 We have our color version up here
2:33 of our external libraries
2:35 not really sure that I'm digging this V2 thing
2:37 so let's do it like that.
2:40 Cool, Rock, Paper, Scissors, this edition
2:42 then if I type this
2:44 we're not quite seeing anything yet are we?
2:48 So let's go back up to the top.
2:50 Our player's logged in.
2:51 The log, it goes to a file.
2:53 It doesn't make any sense, I tried to make it color
2:56 it won't respect that anyway.
2:57 So the next thing to do is
2:58 let's go over here, let's go down here
3:00 let's, for all the errors, give them a color, huh?
3:03 Come down here and say Fore.LIGHTRED or RED.
3:07 There we go.
3:08 So let's go and see if we can get
3:09 a color here that's not so good
3:11 or a output that's not so good.
3:13 So my name is Michael, I want 99, try again.
3:18 Notice we didn't reset it.
3:20 So let's see, we could do that.
3:23 Fore.WHITE again.
3:25 There's some cool coding techniques and stuff
3:27 that we could use
3:28 little data structures that we could come up with
3:30 to have that automatically reset
3:32 but for now let's do it like this.
3:33 It's going to be Michael and 99, try again.
3:37 See how easy this is?
3:38 For us to see what's happening?
3:40 Okay, let's see.
3:42 For the round we're going to roll these things.
3:44 player_1 rolls this.
3:45 Let's make it really clear who's rolled what
3:47 so for you the player what are we going to use?
3:51 Let's go with some yellow.
3:54 For your opponent let's have a light blue
3:56 and then let's reset it like that.
4:00 Keep going.
4:01 And by the way, I'm running
4:02 because it's more clear, the color stands out more
4:04 but you can run it in PyCharm and see those colors.
4:07 You see them down here for example.
4:10 Do 99.
4:11 It comes up but it's not quite as clear
4:12 because the gray background.
4:15 So let's go and keep running up here.
4:18 Michael, 99, no, let's play again.
4:20 I'm going to throw some sponge, love some sponge.
4:23 Michael rolls, roll sponge?
4:26 Computer roll scissors.
4:27 This should really stand out here.
4:29 Who takes the round
4:30 maybe even the scores here we could do some work.
4:36 Fix the S, and here we can put
4:39 we don't want to log that for thing
4:41 so we want to put that here on this output.
4:43 We could do this
4:44 we could even say something like this
4:46 we could say four equals the four there.
4:49 I could say this if winner equal to player_1
4:55 else that means you've lost
4:57 so Fore.RED, light red, something like that.
5:00 Let's try that here, I think that'll be fun.
5:02 So come down here, I'm going to be Michael.
5:04 I'm going to throw some scissors
5:06 oh, we didn't put it back, did we?
5:08 Look, I won the round!
5:12 We could do it like this.
5:13 White and the same message there, that should do it.
5:16 Okay, try again.
5:17 Michael, throw some sponge.
5:19 Computer takes the round
5:21 I'm going to throw some air, some more air
5:23 aw man, that computer is tough.
5:25 Let's try two, three, three, it was tied.
5:29 Computer takes the round.
5:30 I'm telling you, this computer has got my number
5:32 I cannot beat this thing.
5:34 Seven, two, yes!
5:37 I've taken a round!
5:40 Remember it was kind of hard to scan this
5:41 you had to read over it, What's going on? and so on.
5:44 We're also going to improve this
5:46 so it doesn't take up so much space later
5:47 but for now we're getting our color there
5:49 and then, yeah, we're pretty much done.
5:52 Let's do one more thing here
5:54 for this color here.
5:55 Let's put, yeah we don't need to do it.
5:57 We could print out some stuff
5:59 but we'll keep it there.
6:01 Again we'll say Fore equals
6:03 let's get the same little test here.
6:09 If overall winner is that
6:11 and then we just want to do Fore plus.
6:14 And let's reset it, Fore.WHITE.
6:16 Actually, careful, we don't want to log that.
6:19 Not sure what'll happen if we put that in the text file
6:21 but it's probably isn't good.
6:23 So here, let's play one more round
6:24 take it all the way through.
6:25 Michael, I'm going to play some sponge
6:28 because that's my favorite one.
6:29 They played scissors which cuts the sponge
6:32 aw man, I cannot win.
6:33 All right, I took a round with some rock
6:35 do some more rock.
6:36 Getting close, yes!
6:38 I take the round, and I win the game, incredible!
6:40 But down here we have that
6:42 coming out of the bottom.
6:43 Hopefully you get the sense that
6:45 just this little bit of extra color
6:47 really makes this game easier to play
6:49 and I think a little more entertaining as well
6:51 and it was all made possible by Colorama.
6:54 So Colorama is this public thing out on the internet
6:57 we're able to download it and install it with pip
6:59 into our virtual environment here.
7:01 Even expand it and probably see somewhere
7:04 the packages are installed.
7:05 Yeah, there's Colorama toolkit and others.
7:08 But you don't mess with that, you just leave that alone alright?
7:10 Same thing over here.
7:12 packages, we don't want to mess with these
7:13 but you can see that they're there.
7:15 The best way though
7:17 is to go over here and say pip list
7:19 and it'll show you what's installed
7:20 what version and so on.
7:22 Alright! Very cool, we made our app better
7:24 by using one of these external libraries.
7:27 Well that's a start.
7:28 We used one.
7:29 There's 215,000 plus more to go explore
7:32 see what cool stuff we can do.