Hello and welcome to this video.
In this video I'll be showing you how to use a module.
Once you've created a module you can use the module in any python file.
And the way you do that is by importing the module.
So you type in the keyword import followed by the name of the module.
If the module has different types of object you want to access just a specific object inside that module
you can represented by using the from keywords so you type in from you specify the module name and then
you import what you need from that module.
So this is a module that I created in a previous video is called Salute the P1 contains a function and
it also contains a dictionary.
So what I'm gonna do is create another file and try and use this module by using the import keyword
and also the from keyword.
So let me create a new file first.
So right click I'm going you click on python file and I'm going to call this my on this score module
and click OK.
So that's created a new python file for me.
So the first method and prints you used to import a module called solute which is this module here I'm
going to import the module into this file and to do that you need to add the import statement so you
do import space followed by the name of the module.
My module is called Salute to use the function inside the module.
What I can do is just call the module by its name so I'll say salute dot and then I reference the name
of the function which is C on the score.
Hello and I will passing a variable for the parameter so a person in an argument for the parameter inside
that function.
So before I run this far let's take a look at the module.
So this is what the module is.
He has this function which is what I am referring to and there is a parameter inside that function code
name.
So all I need to do I don't even need to use this print statement here.
I'm just referencing it from this file.
But the only thing I'm doing different is I'm passing in an argument for this name parameter.
OK so all I need to do now is just play this file and it'll output.
Hello.
Blue Line.
Click on play you can see here says hello.
Blue Line.
So this is an example of how you can use a module by importing it into another python file.
You can also access a modules object by using the from keyword.
So what you can do you always do the import at the top so you can save from which is a keyword may specify
the name of the module and then you specify what it is you want to use from the module.
So let's say I want to use the dictionary called fruits.
So I say fruits all right.
So this is the module.
Here you can see I've got a function.
I've also got a dictionary called fruit.
So that's what I'm referencing in this file.
So what I'm gonna do I'm going to comment out.
Line number one so that I know so line number three so that we can see how to use the dictionary from
that module.
So let's say I wanted to access one of the keys from the dictionary inside my module so you can say
this is a key code name.
Well I have to do I'll just come here and can just see print and inside that print function I can reference
the name of the dictionary which is fruits and inside the square bracket.
I just add the name of the key and that should print out the name the value for that key code name.
So if I press the play button you can see he is giving me the value of grapes.
If we go back in to the actual module itself you can see here the dictionary called fruits.
I've got a key code name and the value is grapes which is what I have referred to here on line 5.
So there are two ways you can access a module if you want to access the entire module you chose to import
and then followed by the module name.
If you want to just use parts of the module like I've done here on line two you use the from key words
so you say from then the name of the module and then you import what it is you need from that module
like have to on here on line five.
So just for reference the fruits which is the dictionary inside that module.
Okay.
So that is how you can use a module.
Once you have created the module.
Thanks for watching.
Bye for now.