1 00:00:00,000 --> 00:00:03,000 So you can use existing Python modules, 2 00:00:03,001 --> 00:00:07,000 but you can also create your own module if you want to. 3 00:00:07,001 --> 00:00:09,000 Here I'm not going to explain every possible thing 4 00:00:09,001 --> 00:00:13,000 about module creation, just the basics to get you started. 5 00:00:13,001 --> 00:00:18,000 And I'm going to go back to the add to inst.py that we have written previously. 6 00:00:18,001 --> 00:00:22,000 Here we have a function to add two numbers. 7 00:00:22,001 --> 00:00:25,000 Let's say now I want to use that function in a different file. 8 00:00:25,001 --> 00:00:28,000 So what I'm going to do, I'm going to copy and paste 9 00:00:28,001 --> 00:00:32,000 this function every time I need to use it, which is really not convenient. 10 00:00:32,001 --> 00:00:37,000 So I'm going to create a new file here, new Python file, 11 00:00:37,001 --> 00:00:42,000 and I'm going to name it my computations.py, 12 00:00:42,001 --> 00:00:46,000 which is going to be the name of the module, my computations. 13 00:00:46,001 --> 00:00:54,000 I'm going to take the function here, put it in my computations.py. 14 00:00:54,001 --> 00:00:56,000 And well, that is simply the module for now, 15 00:00:56,001 --> 00:01:01,000 which contains a file name and then one function. 16 00:01:01,001 --> 00:01:06,000 And so in this module, you can add as many functions as you want. 17 00:01:06,001 --> 00:01:09,000 Make sure you don't add a code like this, 18 00:01:09,001 --> 00:01:13,000 code that is going to run when you call the file. 19 00:01:13,001 --> 00:01:19,000 So just add functions, don't write any other code, just functions. 20 00:01:19,001 --> 00:01:22,000 And now let's go back to the add to inst.py. 21 00:01:22,001 --> 00:01:25,000 I'm going to remove that function. 22 00:01:25,001 --> 00:01:30,000 And so you can see now we have an error, because add to numbers is not recognized. 23 00:01:30,001 --> 00:01:36,000 What I'm going to do, I'm going to do import my computation. 24 00:01:36,001 --> 00:01:43,000 And I'm going to do here my computations.addToNumbers. 25 00:01:43,001 --> 00:01:47,000 So as you can see, when you import a built-in module 26 00:01:47,001 --> 00:01:50,000 or your own module, that's exactly the same thing. 27 00:01:50,001 --> 00:01:52,000 And a module is nothing else. 28 00:01:52,001 --> 00:01:55,000 So a very simple module is nothing else. 29 00:01:55,001 --> 00:01:59,000 It just a Python file with some functions in it. 30 00:01:59,001 --> 00:02:01,000 So here import my computations. 31 00:02:01,001 --> 00:02:06,000 And then I do my computations.addToNumbers, which is the function here. 32 00:02:06,001 --> 00:02:07,000 And I can use the function. 33 00:02:07,001 --> 00:02:09,000 If I just want to import the function, 34 00:02:09,001 --> 00:02:16,000 I can do from my computations import 35 00:02:16,001 --> 00:02:20,000 addToNumbers, just like we did with the OS module. 36 00:02:20,001 --> 00:02:22,000 And now I can just use the add to numbers 37 00:02:22,001 --> 00:02:26,000 without providing name of the module before that. 38 00:02:26,001 --> 00:02:29,000 And this way, so if you add many more functions here 39 00:02:29,001 --> 00:02:31,000 and you just want to use the add to numbers, 40 00:02:31,001 --> 00:02:35,000 you are just going to import the add to numbers function. 41 00:02:35,001 --> 00:02:41,000 And one last thing is make sure to provide a meaningful name for your module. 42 00:02:41,001 --> 00:02:45,000 So here as a test, I just put my in front, my computations. 43 00:02:45,001 --> 00:02:53,000 Make sure to use a meaningful name, which clearly states what this module is about.