1 00:00:00,660 --> 00:00:03,380 Hello and welcome to this video. 2 00:00:03,420 --> 00:00:08,200 In this video I'll be showing you how to use a module. 3 00:00:08,460 --> 00:00:16,290 Once you've created a module you can use the module in any python file. 4 00:00:16,290 --> 00:00:21,260 And the way you do that is by importing the module. 5 00:00:21,660 --> 00:00:27,150 So you type in the keyword import followed by the name of the module. 6 00:00:27,630 --> 00:00:38,970 If the module has different types of object you want to access just a specific object inside that module 7 00:00:39,450 --> 00:00:47,850 you can represented by using the from keywords so you type in from you specify the module name and then 8 00:00:47,850 --> 00:00:52,550 you import what you need from that module. 9 00:00:52,560 --> 00:01:03,510 So this is a module that I created in a previous video is called Salute the P1 contains a function and 10 00:01:03,510 --> 00:01:06,460 it also contains a dictionary. 11 00:01:06,480 --> 00:01:15,410 So what I'm gonna do is create another file and try and use this module by using the import keyword 12 00:01:15,450 --> 00:01:17,380 and also the from keyword. 13 00:01:17,390 --> 00:01:19,340 So let me create a new file first. 14 00:01:19,350 --> 00:01:30,500 So right click I'm going you click on python file and I'm going to call this my on this score module 15 00:01:31,310 --> 00:01:32,500 and click OK. 16 00:01:32,960 --> 00:01:36,060 So that's created a new python file for me. 17 00:01:36,680 --> 00:01:46,280 So the first method and prints you used to import a module called solute which is this module here I'm 18 00:01:46,280 --> 00:01:52,310 going to import the module into this file and to do that you need to add the import statement so you 19 00:01:52,310 --> 00:01:57,360 do import space followed by the name of the module. 20 00:01:57,500 --> 00:02:03,770 My module is called Salute to use the function inside the module. 21 00:02:03,770 --> 00:02:12,110 What I can do is just call the module by its name so I'll say salute dot and then I reference the name 22 00:02:12,170 --> 00:02:14,920 of the function which is C on the score. 23 00:02:15,710 --> 00:02:28,310 Hello and I will passing a variable for the parameter so a person in an argument for the parameter inside 24 00:02:28,850 --> 00:02:30,950 that function. 25 00:02:31,040 --> 00:02:34,320 So before I run this far let's take a look at the module. 26 00:02:34,430 --> 00:02:35,900 So this is what the module is. 27 00:02:35,960 --> 00:02:42,410 He has this function which is what I am referring to and there is a parameter inside that function code 28 00:02:42,440 --> 00:02:43,500 name. 29 00:02:43,500 --> 00:02:49,300 So all I need to do I don't even need to use this print statement here. 30 00:02:49,520 --> 00:02:51,690 I'm just referencing it from this file. 31 00:02:51,950 --> 00:02:59,970 But the only thing I'm doing different is I'm passing in an argument for this name parameter. 32 00:03:00,500 --> 00:03:06,150 OK so all I need to do now is just play this file and it'll output. 33 00:03:07,110 --> 00:03:07,900 Hello. 34 00:03:08,030 --> 00:03:09,550 Blue Line. 35 00:03:09,590 --> 00:03:13,140 Click on play you can see here says hello. 36 00:03:13,160 --> 00:03:13,690 Blue Line. 37 00:03:14,120 --> 00:03:23,960 So this is an example of how you can use a module by importing it into another python file. 38 00:03:24,050 --> 00:03:31,670 You can also access a modules object by using the from keyword. 39 00:03:31,670 --> 00:03:39,920 So what you can do you always do the import at the top so you can save from which is a keyword may specify 40 00:03:39,920 --> 00:03:46,520 the name of the module and then you specify what it is you want to use from the module. 41 00:03:46,520 --> 00:03:51,080 So let's say I want to use the dictionary called fruits. 42 00:03:51,080 --> 00:03:53,770 So I say fruits all right. 43 00:03:53,810 --> 00:03:55,490 So this is the module. 44 00:03:55,490 --> 00:03:57,440 Here you can see I've got a function. 45 00:03:57,500 --> 00:03:59,560 I've also got a dictionary called fruit. 46 00:03:59,600 --> 00:04:02,040 So that's what I'm referencing in this file. 47 00:04:02,340 --> 00:04:05,410 So what I'm gonna do I'm going to comment out. 48 00:04:05,900 --> 00:04:15,910 Line number one so that I know so line number three so that we can see how to use the dictionary from 49 00:04:16,360 --> 00:04:18,220 that module. 50 00:04:18,260 --> 00:04:26,380 So let's say I wanted to access one of the keys from the dictionary inside my module so you can say 51 00:04:26,380 --> 00:04:27,860 this is a key code name. 52 00:04:28,450 --> 00:04:38,950 Well I have to do I'll just come here and can just see print and inside that print function I can reference 53 00:04:39,550 --> 00:04:45,630 the name of the dictionary which is fruits and inside the square bracket. 54 00:04:45,670 --> 00:04:57,040 I just add the name of the key and that should print out the name the value for that key code name. 55 00:04:57,070 --> 00:05:03,240 So if I press the play button you can see he is giving me the value of grapes. 56 00:05:03,260 --> 00:05:11,300 If we go back in to the actual module itself you can see here the dictionary called fruits. 57 00:05:11,320 --> 00:05:18,970 I've got a key code name and the value is grapes which is what I have referred to here on line 5. 58 00:05:18,970 --> 00:05:26,620 So there are two ways you can access a module if you want to access the entire module you chose to import 59 00:05:27,130 --> 00:05:28,840 and then followed by the module name. 60 00:05:28,900 --> 00:05:35,590 If you want to just use parts of the module like I've done here on line two you use the from key words 61 00:05:35,590 --> 00:05:42,340 so you say from then the name of the module and then you import what it is you need from that module 62 00:05:42,400 --> 00:05:45,340 like have to on here on line five. 63 00:05:45,340 --> 00:05:53,640 So just for reference the fruits which is the dictionary inside that module. 64 00:05:53,640 --> 00:05:54,190 Okay. 65 00:05:54,220 --> 00:05:58,280 So that is how you can use a module. 66 00:05:58,510 --> 00:06:01,290 Once you have created the module. 67 00:06:01,330 --> 00:06:02,560 Thanks for watching. 68 00:06:02,590 --> 00:06:03,240 Bye for now.