Placeholder Image

Subtitles section Play video

  • what is going on.

  • Everybody welcome to Part 15 the final part to the Python.

  • Three basics.

  • Siri's and then you guys were getting kicked out.

  • There are just a few more things I want to show you guys, Uh, let's go ahead and get into it.

  • So the first thing I wanna talk about his packages with Python so you know the reason why Python?

  • It's such a popular language in such a powerful language.

  • Yes, it's easy to write.

  • Yes, it's fast, too, right?

  • Yes, it's easy to read all those things, but there are other languages that meet those criteria, like R and Julia and Ruby and other ones that I can't think of right off the top of my head.

  • But there's lots of other high level languages, like pythons high level because it's very far from the hardware level, as opposed to like.

  • C++ is a lower level language but still classified as kind of a high level language.

  • Anyways, there are lots of languages like python, but why is Python the best?

  • In my opinion, it has to do with the community around Python and not just cause we're all really good people were fun to hang out with.

  • Um, it's It's because of the third party packages that are available with Python.

  • That's what makes Python so powerful because actually, what truly powers Python?

  • It's C.

  • So So Python is really just kind of like it's like this constant ap I slash rapper around another wise, much faster language.

  • So what makes Python the greatest is the packages, so that the main thing I want to talk about here is using third party packages with Python.

  • So there's a bunch of different ways you're gonna get third party package is the main ways with pip, which I'm gonna show you.

  • But I also want to talk about some of the other ways and what even is a package.

  • So you just understand that these things are not magical or anything.

  • So the first thing I'm gonna do is bop into tutorials, and I'm gonna copy testing grounds.

  • We'll go into testing grounds as well, and I'm also gonna add it testing grounds here, to be example mod.

  • So that's just example mon dot pie.

  • Great.

  • So the first thing I want to talk about is, I guess, let's talk about one of the more basic ways.

  • You might install a package so most of time, it'll be via pip.

  • Sometimes it'll be a package that you can only find on get hub, but you still want to install it.

  • If the package comes with a set up dot pie file, you can just use the following so we can go to our command, prompt and then using python and whether the version you want pie 37 In our case, if it had, you would.

  • First of all, you need to be in the directory that has set up a pie, but then you would just run pie 37 set up dot pie install.

  • That's it.

  • Um, so So you would do that if it had a build.

  • You might also build, but it would be in instructions.

  • Most of the time.

  • It's just set up a pint.

  • Install.

  • Very simple.

  • So, um, so that's one way you would do it, but that's kind of a dying method.

  • Now that's one of the older ways used to install packages.

  • We don't really do it that much anymore, but sometimes there will be a thing on Get up that doesn't have ah python package index thing for whatever reason, so you can use this.

  • Um, but let's also talk about what even is a package.

  • Like what?

  • It's a library with a thing we can import because we have made these imports.

  • But we don't maybe understand how that works.

  • So the first thing I want to do is, in example, mod dot pie.

  • Let's just define do a thing.

  • It's gonna pass nothing.

  • And for now, we'll just have a print doing something really cool.

  • And that's all our example Mom's gonna do just a simple function just to give you an idea.

  • So then now coming over and keep in mind.

  • Example.

  • Mine is in the same directory as our testing grounds is so now, coming into testing grounds, we can import example Mont Import.

  • Example.

  • Mod.

  • And when you import something's gonna look for in three places, it's gonna look locally.

  • It's gonna look in your standard library location, and then it's gonna look in your eye.

  • Third party library location, Which is you.

  • It's in your python insulation than lib.

  • Then sight dash packages should be in there.

  • I might have that wrong pressure.

  • That's the path, though, anyway.

  • it's gonna look at all those locations, and this is why it's really important to because it looks locally.

  • It's important to never name your script that the name of the package you intend to use because you'll wind up just importing the script that you're writing.

  • Then you're gonna get some weird attributes.

  • Air.

  • I see it all the time.

  • This is probably the number one error that people asking comment sections on tutorials of mine.

  • They're like, Hey, I'm getting this weird error.

  • I'm like you named your script, The thing you're trying to import and you're importing yourself.

  • Stop it.

  • So anyways, watch out for that.

  • So, import example.

  • Mod.

  • So this imports this script, right?

  • So it's gonna look when it goes to import any directory or file named example, Mon.

  • Not any file.

  • It would just be a dot pie file.

  • So we've imported example mind or a dot P y Z.

  • Anyway, we've imported example mod, uh, let's go ahead and show how we might use it.

  • So you could use example mod dot What does it do?

  • A thing I think it was.

  • Do a thing.

  • Yeah, so we can run this and we can see.

  • Cool.

  • It just did something really cool.

  • We just imported it.

  • Nothing you do is import something from, ah, file.

  • So we could instead say from example, mod import, do a thing.

  • And then we don't need example, mont dot We just use the function.

  • Boom.

  • Um, same thing again.

  • Pretty cool.

  • Now, the other thing we can do is we can do, um, let's just make a new function here.

  • Second function define do do another thing and print, uh, do some some other cool thing Say that import do a thing.

  • And then what was it?

  • Do another thing s Oh, Then you could do a comma.

  • Do another thing we can say that.

  • And then let's copy this.

  • Come down here, paste.

  • Run it again and you can see Okay, we've imported these two things from example mod.

  • Now, another thing that you can dio is if you were gonna import a lot of functions, you might use a wild card like this.

  • So this is just almost like a regular expression for everything or a wild card that just means all the things So we could do that and we can run this but this makes your code pretty hard to read.

  • First of all, because that someone's reading your code and, like, do a thing.

  • They're curious what is do a thing.

  • They're gonna have to do some digging to figure out.

  • Where the heck did that come from?

  • Because, like, say, like in the case where we have only one import the wild card.

  • Okay, we know where that came from.

  • Probably first, though, we're gonna have to comb through the entire script that, you know, maybe it's thousands of lines.

  • See, if this function has been to find in here and then we'll have to go to the import.

  • Be like, Okay, It's an example.

  • Mod somewhere, you know.

  • But the worst thing would be like, What if What if you just continued using these wild card imports like, you know, inside of example, MoD.

  • You've got some wild card import.

  • It just makes it really annoying toe read someone's code that's used these.

  • So my suggestion to you is don't do it, but sometimes people will do it.

  • And so anyway, just No, that's the thing.

  • The other thing you could dio is, um, you can import a thing as a thing.

  • So not only could we have imported example mod is a thing we could also import, do a thing as dat short for do a thing so that we can come down here and we can actually just run dat.

  • We've basically kind of, you know, renamed the function and we run that again.

  • So So that's pretty cool as well.

  • Also, let's say you've got a lot of scripts in a thing that we would more likely call a package.

  • Like in this case, it's just a single script that we're gonna import.

  • I wouldn't call that a library or a package.

  • Well, you would call a package is like a group, a cluster of scripts.

  • So let's make a new folder and I'm gonna call it a mod dir.

  • And then I'm gonna take example mod here, and I'm just gonna put it into my dirt.

  • So then you might also do something like this.

  • So from mod er dot example mod import, do a thing print or no, we don't have to print that.

  • We just run, do saying boom.

  • Okay.

  • And so that's how you could have, like a group of scripts inside of a directory and reference one of them specifically.

  • Okay, I think that pretty much covers.

  • Ah, the mean the extreme basics of what a module is.

  • It's not that complex.

  • In most cases, it's just a python file.

  • In some cases, it does get a little more complex because it's really a python wrapper around C code s so it does get a little more challenging and especially historically, it was very challenging to work with Windows in this way.

  • But lately, all the sea wrapped packages that I've seen installed very easily with what's called Pip.

  • Now Pip stands for Lissy.

  • Pip installs packages.

  • So it's one of those like recursive acronyms like PHP or something silly like that.

  • Um, and so of the Python Package index is what Pip kind of communicates with.

  • So here you can search for projects and stuff like that to figure out what you want to install, and then you really just install it with Pip.

  • Now the thing to keep in mind now that you've learned what a package actually is, it's just python code.

  • So remember, it's easy to forget.

  • What are you doing when you install a package?

  • Because it's a Z Z is going to your command line, and we did it with, like, numb pie in one of the videos, I think was the last one.

  • Pip installed, numb pie.

  • You know, you just run that thing and you don't really think much about it.

  • But the thing is, you're you're plausibly bringing in a lot of code.

  • And then when you use numb pie when you import numb by whatever is in like a main lube or are not a main lou but a main function to run or when you initialize that thing that you've installed, you're pleasantly running a lot of code.

  • And it's in a way that a firewall is less likely to catch because it doesn't look a suspect as you running some crazy dot e x e file.

  • So pay attention and think about what you're doing here, because when you're installing a package from Pip, you are trusting someone else's code.

  • You're just taking it unless you're reading every line, which I know you're not like.

  • You have to understand what you're actually doing.

  • And because of this, I would really watch out because, like, for example, really recently, um, let's say a python package python package.

  • Oh, my gosh.

  • Package index mulish.

  • Yes, just the other day.

  • Here we go.

  • Six days ago on this website.

  • They're talking here about six packages they found to contain malicious code on the python package index.

  • Now, it's hard to see this table, but if I zoom in, you'll you'll see that.

  • Like, for example, this is intending toe thio to mimic the package.

  • Django, for example.

  • But you see, they called it d ang.

  • Go.

  • So it's it's for people who accidentally typo.

  • And it's the Django package, plus some stuff, okay?

  • And you don't want it.

  • All right?

  • In at least in this case, what they were doing was any time you entered, like, a Bitcoin address, it would just change it to a different Bitcoin address that whoever was doing this, um and that's what that was doing.

  • But it could do all kinds of malicious things.

  • And so you just need to be careful.

  • So, you know, check and recheck the package name, maybe go to the official package on the python package Index.

  • Looking to see I don't even know.

  • Usually I don't even look here.

  • It would be cool if they said how many installs were used.

  • You also could look at their get hub page like this one doesn't appear to, which is weird, cause I swear, text rap isn't that new, But what what say we went to Django?

  • Um, look at Django to see if their stats are good.

  • So here, you can see Okay, on their get hope, they've got quite a few.

  • Um, I don't know what it would look like before, but the other thing you could always do is go to their get hub and just, you know, confirm you've got the package name, right?

  • Okay.

  • Anyway, pay attention, That stuff.

  • And then you can see here all you have to do is use pip to install, So we're not gonna use jango.

  • In fact, I'm going to use Color Rama, which was one of the affected packages.

  • So it was type O to be the European spelling, I guess of color with you.

  • But the proper one is pip.

  • Install color rama, and so we can assault that way.

  • Also, I'm just trying to get myself into the habit of always using the specific version soap I dash three seven Dash and Pip install colora MMA like so and that will give us the color Rama package.

  • Now when you get a new package, let's just Google color Rama.

  • There's a variety of ways, um, that packages will document themselves and everyone no one's documentations as good as everybody else's.

  • So, um, you just kind of like everyone's documentations a little different.

  • So some packages have unbelievably great documentations, really easy to use.

  • Other packages don't and then, in terms of, you know, complexity, they all very color Rama's pretty simple library.

  • So their documentation is basically right here on this page.

  • But certain things like Django like will have either their own website or there's a website called Read the Docks, and that's a pretty popular documentation website.

  • And so it just kind of depends.

  • But usually you could just go through the documentation and learn how to use the packages.

  • So, for example, I scroll on down here and I basically just scroll like here's the main thing.

  • I just scroll till I see some text that is, um, code.

  • So in this case, I can see OK, so to use colora MMA.

  • Okay, I need to initialize it.

  • All right.

  • Looks like on windows.

  • We need to run in it on the other platform.

  • It doesn't matter.

  • So this is just a cross platform, Okay?

  • Now, to get it to print colors, all I have to do is apparently you do this, Then you add to the strings.

  • So this is probably it's building the string, um, using the plus here.

  • So?

  • So this four dot read private corps responds to a bit of code.

  • That probably looks really complex to you.

  • Um, so, for example, of this anti sequence here like this is probably more so What?

  • It actually looks like what this will translate to, but this is, you know, a little more easy for us.

  • Tow to type.

  • So it looks like we could change the foreground background style, and then we can reset everything.

  • And one thing to note is like when you change colors, you, um you have to change them back.

  • So when you say four red, that means everything that comes after that is gonna have a red foreground, so pay attention.

  • Okay, so let's go ahead and let's just First of all, it's like, just use color Rama really quick in our testing grounds, Uh, in probably in sublime.

  • It's not gonna work so well, right in sublime.

  • But they will have to run in the terminal.

  • Most likely so first of all, let's do, um In fact, let's just run the sample, actually, So here is the sample and notice the sample doesn't have in it.

  • So we'll have to add that.

  • Let's just pace that in, uh, comma in it and then, innit?

  • Not emit in it.

  • Okay, save.

  • Let's run that.

  • I don't think it's gonna work.

  • It doesn't I don't think you know.

  • So we definitely not running in the terminal.

  • That's not really surprising, uh, to do.

  • Where am I?

  • Here we go.

  • So here, pie dash 37 testing grounds dot pie.

  • And you can see, um, we got spread text, some green text, and then back to normal.

  • And in fact, it's kind of weird.

  • I am on a V m.

  • So maybe that's why it looks so funky.

  • But that looks pretty.

  • That's like, really ugly looking text.

  • I don't know why this is really crisp and clear, but that text was not let me go properties.

  • It's already quite large.

  • Let's go.

  • 72.

  • I don't really want it that big.

  • We'll go 36.

  • Let's use Just try a different fault.

  • Font over.

  • They didn't screw anything up, but we'll find out.

  • Okay, Whatever.

  • So, uh, next I want to do is, uh, let's add this now to our tick tack toe game, because this is all fine and dandy, but let's actually, like, change something in tick tack toe or actually use the package because demos are always different than actually using it, or you just don't realize certain things.

  • Right?

  • So, uh, what I want to do is bop into to trail 14 I think a copy paste that call that call this tutorial.

  • 15.

  • Now, right, click it open up in super lame, and I'm gonna exit out of there and let's go to the Actually, first we need to bring in, um colora MMA.

  • So let's go to testing ground.

  • And we just want to import Well, really, all of this.

  • So copy.

  • Come over here paste.

  • Um Then what we want to do is go down to where we display the game board, which is here, where we print the rope here So this is where we're actually displaying the game board.

  • And what we'd like to do now is make it pretty.

  • So, uh, do okay, so rather than print count row, we still wanna probably print count.

  • But we want to modify the roe little bit.

  • So what I'm gonna do is I'm gonna make a new I'm gonna make a new, uh, variable, and I'm gonna call it colored Row because we need to build the Rose string.

  • So I'm gonna say, Colored Row and for now, it's gonna be nothing.

  • And then we wantto iterated over each item in the road.

  • So what is each item in the road gonna be?

  • Was only three things.

  • In this case, it is a three by three.

  • It'll be.

  • It'll start off his all zeros, and then as players play, it's either gonna be a zero a one or a two.

  • So what we want to say is four items in a row, then what we want to say is if if the item is equal to a zero, what do we want to do?

  • Well, we're just going to say colored row, um, plus equals And in this case, we don't want anything.

  • We just want to empty space.

  • Now it was going to be a space, a comma, the number and then a space again.

  • So I think Earth Spacey Between each I'm gonna put two spaces for now, it might be an extra space.

  • We'll figure that out in a moment.

  • Um, then if item actually, we should make this LF l If item double equals a one, let's say colored row plus equals.

  • And then in this case, how do we do it?

  • Let's let's make one's a green So we could make it would be four dot green plus the thing that we want it to be.

  • So I'm gonna copy this right here.

  • I'm gonna come over here paste four dot green.

  • Uh, actually, I think it's all caps green and then forgot Green.

  • Plus the thing that we want in here.

  • So in this case, I'm going to make that, um, a space the thing.

  • And let's make player one ex while we're here making this happen, might as well do that.

  • So x and then a space on both sides because you got the space in the Kama.

  • So, um, so we make that four grand green.

  • Now, one thing to know is as we do this, this has now changed the foreground to be green.

  • So then after this, if it's zero, notice how we didn't do anything.

  • So we could either, you know, reset at this point, or we need to reset after every, you know, colored letter.

  • So I think I'm actually gonna reset it after the letter.

  • So I'm gonna say, plus style dot Reset, underscore all.

  • And this will get us back to, you know, whatever the default color is, And then we want to do the exact same thing, except for number two.

  • So then I'm gonna come down here if it's a two, and then here will do magenta, and it's gonna be an o.

  • All right, so then rather than print row and count up here, let me just cut this and they will come down here to, uh uh, back to Okay, now, print count.

  • Sure.

  • Whatever.

  • Uh, and then, uh, colored row.

  • So now we'll get the beautiful, beautiful colored rose.

  • Hopefully, let's see what happens.

  • So we come up into our consul now, And let's, uh, pie dash points event.

  • I'm so used to type in 36 tutorial 15 dot pie.

  • Let's do it three by three so you can see it's currently totally empty.

  • Let's play a one in a one, and we need to fix our space in a little bit.

  • There probably need a one space over.

  • Let me play a ah to one.

  • Okay, so I think our initial spacing we just needed We need to space it over ever so slightly.

  • So let's have one more space to the Let's see colored row zero.

  • So, really, actually, everything should be issued.

  • Everything needs Thio take up three spaces.

  • I think so, Actually, let's make that three spaces there because it's a space.

  • The thing in a space, because before it was a space than the number and then a comma, so it should be three spaces.

  • So let's say save that.

  • Come back out here.

  • We run this again.

  • It's a three by three.

  • Let's go 11 Okay, now it's lined up right?

  • And then let's run a 1 to 1.

  • And then, uh, let's go 10 and then to zero and then 12 Congratulations, player.

  • One has won, but it was.

  • Now we have beautiful, beautiful colors.

  • Awesome.

  • All right.

  • And now for a few more Easter egg e type things if we run python, one thing is to import anti gravity gravity.

  • And you get this nice little comic about basically what it's like to use the wonderful language that is Python.

  • I'll let you read that in your free time.

  • The other thing is in Python whenever there is a future change, maybe in a different language, and then we want back poured it to another language.

  • We can do that.

  • So the way to do that is from future, and then you import the thing from the future.

  • And one of them that we can do is braces.

  • And then we get kind of this goofy syntax error that just has not a chance.

  • Eso I wouldn't expect a braces to be in python anytime soon.

  • Okay, Um, there is one last thing for me to show you, but I'm gonna leave that for the end.

  • Um and we are done on and I know you guys.

  • You still gonna feel green.

  • You're still gonna feel new.

  • That's normal.

  • You're gonna feel that way for years.

  • So the best thing that you can do is get out there and start actually working on things that are exciting to you.

  • When I learned Python, the thing I was trying to learn was to do sentiment analysis in natural language processing, like That's why I learned a program in the first place and most people would have been like Oh, that's a horrible beginner project.

  • But for me, it was perfect because it was what I was interested in actually doing, and so because I was excited about it, it made learning Python easy.

  • And that's why I think basics are, you know, it's important that we just get out of the basics as fast as possible.

  • Is there a bunch of stuff that I did not cover that we would consider to be basic Python?

  • Definitely mean We left a lot of stuff, like even dictionaries.

  • We just barely grazed them, so I felt like it would be a sin not to show you dictionaries, but there's a lot of stuff that we didn't cover.

  • And then some people have been asking about, like, object oriented programming, stuff like that.

  • If you go to Python programming, that net click on the fundamentals here and then go to the Intermediate Python Siris.

  • Um, this serious has, ah, lot more concepts to it in terms of more advanced things.

  • And then also object during a programming is done here and we go quite a bit through that, including, like doing special methods and all that kind of stuff.

  • So if that's what you're looking for, it already exists.

  • It doesn't need to be in this Siri's now.

  • This series was really just to get you understanding python and then get out.

  • And then I actually work on projects that are fun.

  • If you want some ideas, come to the home page.

  • Click on stuff that interests you.

  • You can also go to the python subreddit so reddit dot com slash or slash python That'll take you to you know, the recent goings ons and happenings in python right now s so you can get ideas on projects, see what other people are working on.

  • There's also learn python eyes, another one.

  • So there's that You can also come and join the discord.

  • Discord org slash Centex will take you to an invite for the syntax server, and you can chat with a bunch of other people.

  • Um and yeah, I mean, that's that's basically it.

  • So just get out and start working on stuff that's exciting to you, and you're gonna pick up and learn python on the way.

  • When you hit concepts, you don't understand.

  • Google it when you hidden area, you don't get Google it.

  • It's it's really simple.

  • Toe learn python.

  • It's just, um, yes, stick with it, not get burnt out.

  • And I think the best way to do that is, um is to work on stuff that's exciting and interesting to you specifically, and that's not gonna be found.

  • I don't think in the basics course.

  • So, Anyways, I'm gonna leave you guys with the last thing that you should important.

  • I'll let you read it on your own screen.

  • But you can import this, and this will give you the Zen of Python by Tim Peters.

  • And it's just kind of a good little thing to kind of live your life by when writing python code justice.

  • Something to continue continually.

  • Remember and look at your script and see a my violating these things.

  • It's just kind of a good way to a good thing to keep in mind as you code.

  • So anyways, you can read that on your own.

  • That's it.

  • That's the end of the Siri's quick shout out to the most recent sponsors, Siraj, Dish, Muck and Stark's Gamma.

  • Sorry if I just totally butcher you guys.

  • His name's I apologize as usual.

  • If you don't know how to sponsor or become a member or whatever we want to call it, you can click that beautiful blue doing but in, That's it, guys, get out of here.

what is going on.

Subtitles and vocabulary

Click the word to look it up Click the word to find further inforamtion about it