 What's up guys, Root from NullShall.com here today and we're looking at some more Python. I'm gonna get Idle fired up and we can get right to programming. I'm gonna create a new window first of all, control N to get that started. We'll put Python shell in the center today. And then we'll save this as something different. I'm gonna call mine outside. And now I'm gonna get my shebang line started, environment, Python. And I'm gonna create a new class. Wouldn't call this class external. Just because I think that's a fancy name, you know? Let's get a constructor going with the init keyword wrapped in two underscores. But at the beginning and the end, we'll have the self keyword to be passed in as an argument. And what we'll do is we'll have this little thing print. Uh, hello. I am from outer space, but I come in peace. And you know, let's give it some tabs just to make it look, just to make it look a little bit more elegant. And remember these escape sequences, the escape characters backslash n, backslash t, and that sort of thing. So, okay. Now we have our, let's, let's set something up. Let's get alien can be equal to external. We run this. Hello, I'm from outer space, but I come in peace. So we've created an object here, but now we want to, we want to use this in a more broader scope in a broader sense. So what we're going to talk about today is something called modules, or, or libraries, or it's, it's lots of external code that you can call, or at least retrieve the information from to bring it back to your own program. So you can do a lot of stuff with this. You could import some libraries or modules that allow you to have a bit more functionality. You can use the RE module that will give you access to regular expressions. You can use a GTK, which will give you access to a graphical user interface calls. You can use a URL libs to get information from the internet. You can use, you can use OS to get information from the operating system. And there's, there is so much out there, especially when it comes to modules and like external things that you can import. And import is a keyword that we're going to be looking at today. There's so much you can import that there's so much you can do that you have to be able to like know the information. You have to know how this module works, how the things are set up, the language, the way that it works. It really, I'm saying it a lot of times because it really, that is the most crucial bit. You have to know how the module or the library is set up. So you know the calls, you know the syntax, you know the way it works and that sort of thing. I'm going to stop talking. I'm saying the same thing over and over again, whatever. But yeah, let's try it out though. The keyword we're looking at is import, or import, obviously, and you can import and then the name of the module that you're importing. You can use OS. You can use Sys. You can use Pygame. You can use GTK. You can use RE. You can use, what am I thinking, URL lib. You can use sub process. There's so much out there, but you'd have to have the knowledge and information of knowing that exists. So in our case, we're going to do something a little interesting today. We're going to create from scratch our own module. And this is convenient too because let's say you had some variables or some functions that you wanted to save. Maybe you created a function that you use a lot and you want to keep track of that, except you don't want to have to bother rewriting it and rewriting it every time. So what you can do is you can import it to each program that you write. So let's get started though. Let's create a new window. I can create a new script and I'm going to call this control. And that's all. I'm just going to call it control.python. So get my shebangline, usrbin, environment, Python. And then I'm going to create a new class for this one. And I'll call this base just for regular, that sort of thing defined in it. So we have constructor, things that happen automatically. Self as a keyword, obviously, yada, yada, yada. How many times have you guys done this? Tell me, let me know. Hello there. That's all I'll say. So let's say dog. Dog is our base. So we can run him and he just says hello there. So that keeps it easy. Okay, so now there's dog. So let's do something else. Let's import all the code that's inside this outside script. So what we'll do is we'll import outside. Because outside itself is a module. All the information, the code that you've written here, can be used externally, hence the class name external. That's why I wanted to hint at getting things from the outside. Taking things in and that sort of thing. So when you're importing outside, we have access to everything in inside. If we tried this from the shell, we could import outside. And then from outside, we have these things that we can do. We have the external class. So let's try it. We can set an alien in the control script to be from outside. We're going to use our dot selector. So we're getting things from this module. And we can use the external class. We have access to it. So alien is an object or an instance of this external class that we've created in a different script or a different module. So when you run this, alien says, hey, I'm from outer space, but I come in peace. Except we're using him from a different script. So this is kind of interesting though. Because we're able to take information from other files and other code. So I want to talk about something different now though. Because you have this thing where some of, usually one module or one program or one sort of script or the file will be set up for the main thing, the actual root of the program, the thing that does everything that makes the action happen. Like if you had this external class, let's say, sorry, this outside file. And let's say outside was full of different classes. They were all just able to maybe external things, maybe something named fish. Maybe you just had lots of programs that would do stuff with animals or something. Say that, we had fish, we had dogs, and all these other classes. But they don't really do anything. They're just defined. So they're easy to maintain. You know where they all are. They're in one specific file and that sort of thing. So yeah, you would set this file or the outside.python file. You would set that up for defining your classes and defining your functions. And control.python would be the one that actually makes things happen. So because we're importing outside though, if we had things that would normally happen in outside.py, we could just do print this is outside.python. We could run this. This is outside.python. But what happens if we were to run outside and it happens automatically though? We don't want that. So what we're going to do to avoid this is set up an external function like if you have another interesting keyword here, if the name of this name, and then that's going to be wrapped into underscores is equal to underscore main, then this is where you would type your code. This is where you'd be able to type in. Okay, print something and that sort of thing. Print hello there. Hello there. This is outside. And now let's try this from the control. Let's type in if name is equal to main, hello, this is control. So let's run, let's see, actually, why is that commented? What the, what the, what the heck? So this, if we just run outside, we have all these class definitions and eventually we get to some action. We actually display something out on the screen. So if we run this, we can save that. It says hello there. This is outside, but that's because we're running the outside program. If we switch back over to control, we're still importing outside, but outside isn't going to display that because it isn't the current running library. It's not main, control is main. Control is the program that we're running. So control will say hello there, this is control, but we won't see, we won't see hello there, this is outside. So if we run this, this is control, this is control, if we run outside, this is outside. And that's only happening because it's the main function. But when we're including it externally, we don't have to worry about that because we've added this declaration that we should only do these things and make these actions happen if this is the current script that we're running. So there, I think that's all I want to cover today. That might be a little hard to think about and wrap your head around because we're working with two different files here. But remember, we are going to be looking at other external modules like OS or Sys or RE and that sort of thing because there's a lot to cover in the world of Python. And it's kind of crazy and kind of intimidating, I'll be honest. But we'll knock it down one by one. That's just what we do. So thanks again, guys. It'd be cool if you could give me a, maybe leave a like. You don't leave a like. Just click that little button with the thumb sticking up. And maybe leave a comment. That's what you should do. You should leave a comment and hit the like button. And maybe subscribe. I don't know. It's whatever you want to do. But thank you guys again. I'll see you in the next tutorial.