Everybody you the next video.
So in this video we're gonna be going over something called a module.
Now up until this point we've used the defaults and built in aspects of Python.
However there are additional things that have unique features and different things that we want to do
such as interacting with the operating system or making a web request.
Whatever the case might be we have different modules that we can use to accommodate that.
So the way to to to use a module is you have to import it.
So at the very top you do import and then the module name.
Now I'm going to go over a module called you are a link to this is I'm not going to explain how it works
all of its features or anything like that.
I'm just trying to show you when you import something into how you use it there is in most cases when
there's a module especially ones included with Python.
There are documentation online for how to use the particular module such as making a web request with
you are all lives too.
Or using the OS module to interact with the operating system.
Whatever the case might be you're going to want to import it.
So in this case if you are a to.
And then if you want to import more we're going to use OS just to play around a little bit.
So import os so the way this works is you have to a know what the module does and how it works.
Do documentation because there's going to be some examples.
However it uses dot notation too similar to what we are to use where we've done for example we did Temple
s dot append as an example.
So this dot notation is a function or a method inside of the List class.
Now we're going to go over classes later but the list is technically a class so you are all up to.
So if we want to let's say we want to make a web a web request to read to nation dot com right we want
to get the front page so we can set a variable called content and we'll set that equal to you are all
linked to.
So the way this works in this particular module is we import your outlook too and then we provide it
the name of the module dot.
And then what we want to do.
So you are L open and then we'll do a CPS team nation dot com right.
Then we're going to want to do is print content in this particular case and stop reed which actually
opens.
Which which actually reads the stream from the connection.
Now again I'm not going to go over exactly what each of this is going to happen.
However I want you to understand how to access a module each module will have its own unique way to
interact with it based on what you're wanting to do based on the documentation.
So if you do a quick look here and we run this you're going to see unknown.
Oh yeah let's make it an actual URL we see here we should just get a dump of each team LCROSS javascript
they're so easy here.
This is our.
This is the main main page.
That's the source of it.
That's publicly available.
So that's the front page.
So that's how a module works.
However there might be ones where you know maybe we don't want to work with the web page we want to
work on the operating system.
So let's say we want to do we want to interact with optic systems so we'll do we want to list whatever's
in the current directory.
So if we do OS dot system which system is put is a function inside of the OS module and then that takes
a command.
So in this case we do let's dash out we want to see what's in the directory.
So if we go and run this now we can see that is no different than if we just ran that exactly the same
thing.
We can do the same thing for print working directories.
We know what directory we're in and you can see here working directory working directory so that's how
modules work.
Now in this particular course we're not going to go over how to build your own custom module.
There's plenty of tutorials out out there for that.
Now if you do want that particular content feel free to let me know over the Facebook group and then
we can I can throw something together for you guys.
However for now understanding that when you need additional features such as web calls interfacing with
the operating system using threading using any other type of feature that's not comes that doesn't come
standard with Python as far as the standard libraries are concerned.
And you have to use an import such as for example time if we wanted to sleep.
And let tell tell the process to hold on for a second two seconds before it continues for whatever reason
you're going to need to import time.
So if we import time and we do time dot sleep which is again sleep has a function called Time which
takes a parameters will take five seconds so if we run this you don't see it's just waiting here for
a full five seconds and as soon as five seconds is up it will release and come back to the prompt.
Perfect.
So it's important understand the concepts you'll get used to this pretty quickly when you're trying
to build certain tools you'll try to find out how.
Quickest way to make a get web request you're going to find you are a Libs or the requests module.
So depending on what people are presenting as their solution you'll find four or five different modules
that might produce the same thing.
So maybe you want to pass through each team out and you're gonna probably land on a module called Beautiful
Soup so get familiar with the process look up you are libs to OS in time and look at some of the documentation
around that that'll get you a better idea of what options are available and kind of how a module works.