1 00:00:00,060 --> 00:00:09,230 This material on importing packages in the last Victorian we have learned how to create modules and 2 00:00:09,230 --> 00:00:16,530 import these modules into external programmes in this tutorial. 3 00:00:16,550 --> 00:00:22,490 We will talk how to create packages and import the packages. 4 00:00:22,790 --> 00:00:32,510 We have already discussed that a package is basically a directory with Python files and a file with 5 00:00:32,510 --> 00:00:36,500 the name double underscore in it. 6 00:00:36,500 --> 00:00:44,120 This means that every directory inside of the Python part which contains a file named double underscored 7 00:00:44,240 --> 00:00:54,950 in it that b y will be treated as a package by Python and it is possible to put several modules in to 8 00:00:55,010 --> 00:00:56,240 a package. 9 00:00:56,450 --> 00:01:06,050 A package is important like a normal module so we can use the import statement and from statements that 10 00:01:06,050 --> 00:01:08,740 we have discussed in the previous story. 11 00:01:10,420 --> 00:01:18,590 And importing the package is conceptually equivalent to importing the packages double underscored in 12 00:01:18,590 --> 00:01:27,610 a file as a module and when you import or package or a module in a package the double underscored in 13 00:01:27,620 --> 00:01:32,950 nut file is invoked and this file can be left empty. 14 00:01:33,370 --> 00:01:38,620 But we generally place the initialization code for a package. 15 00:01:38,620 --> 00:01:47,380 Say for example we can make sure that some modules are imported or some values are set in the input 16 00:01:47,380 --> 00:01:55,810 file and also only objects that are declared in the import packages in that file are accessible. 17 00:01:57,060 --> 00:02:06,390 In the external programmes or the importer so in the input fi that is created in the basic map package 18 00:02:06,840 --> 00:02:10,490 we are importing three modules. 19 00:02:10,590 --> 00:02:19,320 The first is using the import statement where importing the module addition and then using the from 20 00:02:19,320 --> 00:02:30,950 statement we are importing the function as you be and again using the from statement we are importing 21 00:02:31,430 --> 00:02:37,580 all the available functions in the module multiplication. 22 00:02:37,730 --> 00:02:47,930 So here we have used an asterix in order to import all the functions are all the attributes in the global 23 00:02:48,050 --> 00:02:51,770 namespace of the module multiplication. 24 00:02:51,770 --> 00:03:02,030 So this is the initialization caught in the net fi so I now have my package ready with the different 25 00:03:02,140 --> 00:03:06,040 with the different modules and also the input file. 26 00:03:06,050 --> 00:03:15,110 I'm not going to import the package basic mat from the command prompt so for that I have started the 27 00:03:15,110 --> 00:03:16,800 python interpreted. 28 00:03:17,000 --> 00:03:28,430 You can see the python prompt and before importing the basic math package I'm going to see the attribute 29 00:03:28,490 --> 00:03:35,180 that are available or that are accessible in the current working space. 30 00:03:35,180 --> 00:03:39,700 And for that you can use the d a r function. 31 00:03:39,830 --> 00:03:50,020 So these are the different attributes that are available in the current working space before doing anything 32 00:03:50,080 --> 00:03:52,630 in the Python interpreter. 33 00:03:52,630 --> 00:03:57,800 Now let's go ahead and import the package basic math. 34 00:03:58,240 --> 00:04:00,550 So we have imported the package. 35 00:04:00,550 --> 00:04:01,980 Basic math. 36 00:04:02,020 --> 00:04:13,210 Let us now again see the attributes available or accessible in the current working space. 37 00:04:13,210 --> 00:04:22,410 So as you can see basic math after the import statement has been executed basic math has been added 38 00:04:22,410 --> 00:04:24,120 to this list. 39 00:04:24,180 --> 00:04:33,410 So this package has been added to the list of attributes that add accessible from this space. 40 00:04:33,450 --> 00:04:42,660 So let us try to access the modules and the functions defined in these modules from here. 41 00:04:44,050 --> 00:04:53,560 So we only have the whole package basic math accessible to us and all the modules or the functions need 42 00:04:53,560 --> 00:05:02,260 to be accessed using the dot notation we can't access them directly from here. 43 00:05:02,330 --> 00:05:12,760 So you use the dot notation in order to access these functions are the modules inside the package edition 44 00:05:12,790 --> 00:05:22,210 is one of the modules available in the package and add is a function to pass arguments to this function. 45 00:05:23,050 --> 00:05:23,990 So. 46 00:05:24,310 --> 00:05:35,510 So we were able to access the function and by importing the package basic math by importing the entire 47 00:05:35,510 --> 00:05:36,230 package. 48 00:05:36,230 --> 00:05:47,300 Basic math we were able to access the different functions available in the modules so let's axis the 49 00:05:47,840 --> 00:05:49,650 module multiplication. 50 00:05:49,670 --> 00:05:58,730 Now we will access one of the functions defined in the module multiplication. 51 00:05:58,730 --> 00:06:07,430 So this time we have not used the module but we have directly access the function defined in the module. 52 00:06:07,760 --> 00:06:16,880 That's because we have used the from statement different statement allows individual objects from a 53 00:06:16,880 --> 00:06:22,210 module to be imported directly into the into the calling program. 54 00:06:22,340 --> 00:06:33,510 So the France statement allows individual objects from a module to be imported directly into the culling 55 00:06:33,530 --> 00:06:35,440 programs namespace. 56 00:06:35,480 --> 00:06:42,650 So we have access to this function modeled from the package. 57 00:06:42,650 --> 00:06:53,140 Basic math so that is it is in we have not included the module name multiplication while accessing this 58 00:06:53,140 --> 00:07:04,060 function might we have not used the module name before accessing the function mind that is defined that 59 00:07:04,060 --> 00:07:07,150 is defined in this module multiplication. 60 00:07:07,150 --> 00:07:14,830 That is because the function modeled is added to the namespace of the package. 61 00:07:14,830 --> 00:07:16,360 Basic math. 62 00:07:16,810 --> 00:07:29,520 In order to understand this we use the function D I add and past basic math as an argument to this function. 63 00:07:29,620 --> 00:07:38,180 So as you can see these are the list of list of attributes that are available. 64 00:07:39,600 --> 00:07:41,880 Odd accessible to the. 65 00:07:41,880 --> 00:07:42,610 Package. 66 00:07:42,630 --> 00:07:43,780 Basic math. 67 00:07:44,870 --> 00:07:52,960 And using the import statement we have imported the entire module addition and using the from statement 68 00:07:53,360 --> 00:07:59,550 we have imported the functions mind and sub in dude. 69 00:08:00,630 --> 00:08:02,610 The namespace of the package. 70 00:08:02,610 --> 00:08:04,080 Basic math. 71 00:08:04,080 --> 00:08:09,960 So you can directly access these two functions from the package. 72 00:08:09,960 --> 00:08:11,460 Basic math. 73 00:08:11,760 --> 00:08:16,260 And in my system I have created a directory. 74 00:08:16,260 --> 00:08:20,400 Basic math which contains all these files. 75 00:08:20,400 --> 00:08:25,150 The init file multiplication addition and subtraction. 76 00:08:25,440 --> 00:08:30,760 And these are these modules available in the package. 77 00:08:30,810 --> 00:08:32,610 Basic math. 78 00:08:32,780 --> 00:08:41,930 Apart from the Python script files we also have a folder by cache folder in the package basic math. 79 00:08:41,970 --> 00:08:43,630 Let's go into this folder. 80 00:08:45,460 --> 00:08:57,490 And Python stores the byte code of the imported modules in special cashiered files with the same module 81 00:08:57,490 --> 00:09:01,470 name but using the extension dart. 82 00:09:01,490 --> 00:09:11,980 B why C in the bike cache folder and with this we come to the end of the topic packages and modules.