1 00:00:00,000 --> 00:00:01,200 [no audio] 2 00:00:01,200 --> 00:00:04,300 Friends here our concept is Introduction to OOPS. 3 00:00:04,300 --> 00:00:06,300 See basically Python 4 00:00:06,300 --> 00:00:10,100 is supporting for both procedural and object-oriented programming concepts. 5 00:00:10,100 --> 00:00:13,800 Suppose if you implement any code in terms of functions, then we 6 00:00:13,800 --> 00:00:17,910 can say that we are following Procedural Oriented Programming concepts, 7 00:00:17,900 --> 00:00:20,600 and we have already done this in our previous videos. 8 00:00:20,600 --> 00:00:25,600 Now, here our concentration is on OOPS. Then what is OOPS or 9 00:00:25,600 --> 00:00:28,000 what is an Object-Oriented Programming Concept? 10 00:00:28,000 --> 00:00:29,900 [no audio] 11 00:00:29,900 --> 00:00:33,700 See, it is all about usage of class, object, inheritance, polymorphism, 12 00:00:33,700 --> 00:00:36,100 data abstraction, and data encapsulation. 13 00:00:37,800 --> 00:00:38,800 See suppose 14 00:00:38,800 --> 00:00:41,200 if you are new to programming or OOPS concept, then you will 15 00:00:41,200 --> 00:00:44,000 get confused about all these terms. Don't worry. 16 00:00:44,000 --> 00:00:46,400 You don't need to remember all these things, we'll go with 17 00:00:46,400 --> 00:00:49,200 step-by-step so that you will get an idea on each and every 18 00:00:49,200 --> 00:00:53,800 term, or on each and every concept in your OOPS. But for 19 00:00:53,800 --> 00:00:57,400 time being just remember that, OOPS is 20 00:00:58,500 --> 00:01:02,200 all about the usage of class and object. That's it. 21 00:01:02,200 --> 00:01:05,300 Simply OOPS is a combination of classes and objects That's it. 22 00:01:05,300 --> 00:01:07,000 [no audio] 23 00:01:07,000 --> 00:01:10,410 And the very first important point in your OOPS concept is, 24 00:01:10,400 --> 00:01:14,400 we are using OOPS concept to create an object. 25 00:01:14,400 --> 00:01:16,700 Then what is an object? 26 00:01:18,200 --> 00:01:22,800 See object could be anything which exists in real-time like 27 00:01:22,800 --> 00:01:28,310 human, fan, car, mobile, laptop, mouse, keyboard, or any application 28 00:01:28,300 --> 00:01:33,300 or Jenkins, WebLogic, Tomcat, Apache, or Docker, anything, 29 00:01:33,300 --> 00:01:38,300 or Docker pods, anything you can take as an object. 30 00:01:38,300 --> 00:01:41,900 The only thing is if we take anything as an object it should 31 00:01:41,900 --> 00:01:45,000 exist in real-time. That's it. 32 00:01:45,000 --> 00:01:47,600 And if you go with any object, each object 33 00:01:47,600 --> 00:01:50,400 has some characteristics and functions. 34 00:01:50,400 --> 00:01:53,400 Let's say human or person as an object. 35 00:01:53,400 --> 00:01:57,400 Then, we can say that characteristics are like name, age, 36 00:01:57,400 --> 00:02:01,500 height, color. And functions are like walking, talking and running. 37 00:02:02,500 --> 00:02:06,810 Right. Not only human, you can take suppose 'Apache' as an object. 38 00:02:06,800 --> 00:02:08,699 Suppose if I take Apache as an object, 39 00:02:08,699 --> 00:02:10,500 then I can say characteristics 40 00:02:10,500 --> 00:02:14,709 of 'Apache' is like version, configuration, file of Apache, 41 00:02:14,700 --> 00:02:16,600 that is 'httpd.conf'. 42 00:02:17,800 --> 00:02:21,900 And functions I can say, suppose you know 'Apache' is used 43 00:02:21,900 --> 00:02:27,800 to serve some static pages, that I can treat as a function. But don't worry. 44 00:02:27,800 --> 00:02:31,109 you don't need to remember about characteristics and functions. 45 00:02:31,100 --> 00:02:33,109 By default, while writing your code 46 00:02:33,100 --> 00:02:36,000 you will come to know what you have to take as characteristics, 47 00:02:36,000 --> 00:02:39,000 and what you have to write as a function. 48 00:02:39,000 --> 00:02:41,700 Actually, characteristics are like attributes or variables, 49 00:02:41,700 --> 00:02:46,109 and functions you know, to implement some logic we are using functions. 50 00:02:46,100 --> 00:02:48,600 That's it. But you don't need to remember even these 51 00:02:48,600 --> 00:02:51,000 characteristics and functions for your object. 52 00:02:51,600 --> 00:02:54,510 So here you have to remember that object is something 53 00:02:54,500 --> 00:02:56,100 which exists in real-time. That's it. 54 00:02:56,100 --> 00:02:58,000 [no audio] 55 00:02:58,000 --> 00:03:01,300 Right. So why we are using OOPS? 56 00:03:01,300 --> 00:03:05,209 The first thing is, we are using OOPS concept to create an object. 57 00:03:05,200 --> 00:03:08,209 Then, why we need to create an object? 58 00:03:08,200 --> 00:03:10,400 What is the purpose? Right. 59 00:03:11,600 --> 00:03:13,310 Let me give you the very first point 60 00:03:13,300 --> 00:03:14,410 that is very, very useful. 61 00:03:14,400 --> 00:03:17,100 That is, to group related functions. 62 00:03:18,400 --> 00:03:22,400 To group related functions. Why we need to group related functions? 63 00:03:22,900 --> 00:03:24,200 Let me give an example. 64 00:03:25,600 --> 00:03:29,100 Just assume that you are having two applications in your code. 65 00:03:29,100 --> 00:03:33,500 I mean, let's say you're having some web application. 66 00:03:33,500 --> 00:03:36,410 So in a web application, you're having two apps, let's say 67 00:03:36,400 --> 00:03:44,800 'Ap1' and 'Ap2'. And in your code, for 'Ap1' you define 100 functions. 68 00:03:44,800 --> 00:03:48,800 Just for logic implement. And for 'Ap2' also you 69 00:03:48,800 --> 00:03:51,400 implemented 100 functions. 70 00:03:52,000 --> 00:03:55,600 So, this is for 'Ap1' and these are for 'Ap2'. 71 00:03:55,600 --> 00:03:58,200 So totally you are having 200 functions. 72 00:03:59,300 --> 00:04:01,700 Totally you are having 200 functions. 73 00:04:01,700 --> 00:04:06,700 Just observe that in my logic somewhere 74 00:04:06,700 --> 00:04:13,000 I am calling 'Ap2', 'Ap2_f2' function. Then how your Python 75 00:04:13,000 --> 00:04:15,900 is going to execute. Actually, whenever if I call this function 76 00:04:15,900 --> 00:04:20,000 'Ap2_f2' function, then it has to call 'Ap2', 77 00:04:21,100 --> 00:04:24,600 let's say 100th function. In 'Ap2' I want to call 100th function. 78 00:04:24,600 --> 00:04:27,310 Then your Python has to call this last function. 79 00:04:27,300 --> 00:04:29,800 But how is your Python is going to execute that? How is it going to 80 00:04:29,800 --> 00:04:32,900 pick this function whenever we call in this way? 81 00:04:32,900 --> 00:04:37,500 So guys what I am saying is, let me write here so that you will get some 82 00:04:37,500 --> 00:04:41,200 idea. See I'm having two apps in my code. 83 00:04:41,200 --> 00:04:45,909 Then I am implementing 'app1_f1', likewise, 84 00:04:45,900 --> 00:04:49,300 I am implementing 100 functions for my 'app1'. 85 00:04:49,300 --> 00:04:51,810 [no audio] 86 00:04:51,800 --> 00:05:01,500 'app1_f100. The same way I have 'app2' functions in my code. 87 00:05:01,500 --> 00:05:10,100 Let's say, 'app 2_f1', likewise I define 'app2_f100' function, 88 00:05:10,100 --> 00:05:12,400 100th function. So finally how many functions 89 00:05:12,400 --> 00:05:15,000 I'm having? 200 functions in my code. 90 00:05:16,000 --> 00:05:20,600 So I'm having 200 functions in my code, and somewhere 91 00:05:20,600 --> 00:05:25,700 in my code I am calling 'app2_f100' function. 92 00:05:26,600 --> 00:05:29,300 Just I am calling somewhere in my code this function. 93 00:05:29,300 --> 00:05:32,310 Then how is your Python going to execute that? 94 00:05:32,300 --> 00:05:38,110 See actually, you're having, here 100 functions and here 100 functions, 95 00:05:38,100 --> 00:05:43,409 so totally you're having 200 functions in your code, be clear. 96 00:05:43,400 --> 00:05:47,300 So, whenever if I call this function, how your Python is going to execute 97 00:05:47,300 --> 00:05:50,100 or actually, whenever I call this function you have to execute this, 98 00:05:50,100 --> 00:05:53,000 but how is your Python going to execute? 99 00:05:53,000 --> 00:05:54,810 It will take this function name, 100 00:05:54,800 --> 00:05:56,500 and it will compare with the very first function. 101 00:05:56,500 --> 00:05:58,200 Anyway, there is no match. That's why 102 00:05:58,200 --> 00:06:02,100 it'll skip that. So the first check is a fail. Then we'll check with 103 00:06:02,100 --> 00:06:04,600 the second function, fail, check with likewise 104 00:06:04,600 --> 00:06:09,700 it will check 200 checks. In the 200th check, there is a match 105 00:06:09,700 --> 00:06:12,100 that's why it is going to execute this function. 106 00:06:12,100 --> 00:06:14,100 Now, simply to execute this function 107 00:06:14,100 --> 00:06:16,700 your Python is doing 200 checks. 108 00:06:16,500 --> 00:06:18,500 [no audio] 109 00:06:18,500 --> 00:06:19,900 Right. So instead of that 110 00:06:19,900 --> 00:06:22,900 what I am doing is, let me do in this way. 111 00:06:22,900 --> 00:06:25,210 [no audio] 112 00:06:25,200 --> 00:06:29,010 I am defining these 100 functions for 'app1'. 113 00:06:29,000 --> 00:06:31,600 I am giving some name called, 'app1'. Under that 114 00:06:31,600 --> 00:06:33,409 I am defining 100 functions. 115 00:06:33,400 --> 00:06:37,500 Let's say for 'app2' also I am defining a name called 'app2', 116 00:06:37,500 --> 00:06:40,000 I mean I'm creating two separate blocks. 117 00:06:40,000 --> 00:06:42,800 In 'app1' block I'm having 100 functions, 118 00:06:42,800 --> 00:06:45,000 and in 'app2' I'm having 100 functions. 119 00:06:46,200 --> 00:06:47,800 Right. Now, let me remove this. 120 00:06:47,800 --> 00:06:50,900 [no audio] 121 00:06:50,900 --> 00:06:53,000 Just assumption guys so that you will get an idea. 122 00:06:53,000 --> 00:06:57,900 [no audio] 123 00:06:57,900 --> 00:07:00,700 Now, I am calling the 'app2_f100' function, 124 00:07:00,700 --> 00:07:03,200 then how your Python is going to execute? 125 00:07:03,200 --> 00:07:07,500 Previously to execute this 'app2' function, 'app2' 100th function, 126 00:07:07,500 --> 00:07:10,406 your Python had done 200 checks. 127 00:07:10,400 --> 00:07:12,000 [no audio] 128 00:07:12,000 --> 00:07:15,810 Right. Now, how it is going to check? Whenever if you have a 129 00:07:15,800 --> 00:07:18,710 block concept in your code, under block 130 00:07:18,700 --> 00:07:22,300 I am defining 100 functions here, and under this block 131 00:07:22,300 --> 00:07:24,510 I define 100 functions. 132 00:07:24,500 --> 00:07:28,100 So, whenever if you have a block concept here how is your Python 133 00:07:28,100 --> 00:07:29,710 going to execute your function? 134 00:07:29,700 --> 00:07:31,400 So first it will take the first part. 135 00:07:31,400 --> 00:07:34,710 What is that? 'app2'. With 'app2' it will check here. 136 00:07:34,700 --> 00:07:36,210 Anyway, this check is fail. 137 00:07:36,200 --> 00:07:39,100 That's why it will skip all these functions to check. 138 00:07:40,200 --> 00:07:42,000 So then it is coming here 139 00:07:42,000 --> 00:07:45,100 'app2', yes. There is a map with 'app2', 'app2'. 140 00:07:45,100 --> 00:07:48,700 Now, your Python will try to execute your function by comparing in this block, 141 00:07:48,700 --> 00:07:51,406 so that you are skipping suppose 100 checks here. 142 00:07:51,396 --> 00:07:54,200 [no audio] 143 00:07:54,200 --> 00:07:58,000 Right. So, previously you are having 200 checks to execute your 144 00:07:58,000 --> 00:08:02,300 function, but now we are having only 102 checks. 145 00:08:03,600 --> 00:08:08,210 So one check is, comparing 'app2' with block1. 146 00:08:08,200 --> 00:08:12,300 That is failed. One check. Then 'app 2', that is success. Second check. 147 00:08:12,300 --> 00:08:16,810 Then to execute your 'f100' function in 'block2', we need 100 checks. 148 00:08:16,800 --> 00:08:18,800 Anyway, compared to your previous procedure 149 00:08:18,800 --> 00:08:21,500 now we reduced 98 checks. 150 00:08:22,210 --> 00:08:25,663 That is an advantage for us, right? Speed is high, compared to that. 151 00:08:25,600 --> 00:08:27,800 [no audio] 152 00:08:27,800 --> 00:08:33,000 Now, writing your code in terms of a block is called simply object. 153 00:08:33,000 --> 00:08:37,500 That's it. Writing your code in terms of block is called an object. 154 00:08:38,799 --> 00:08:40,200 But anyway, this is not perfect. 155 00:08:40,200 --> 00:08:42,210 I will give that detailed structure. 156 00:08:42,200 --> 00:08:47,299 So now you got to know that OOPS is useful to group related functions, 157 00:08:47,299 --> 00:08:49,200 so that you are going to save some time while executing 158 00:08:49,200 --> 00:08:52,700 your code. Then the second thing is to create a 159 00:08:52,700 --> 00:08:55,100 template or blueprint. What is this? 160 00:08:55,100 --> 00:08:57,200 [no audio] 161 00:08:57,200 --> 00:08:59,300 We know generally what is meant by template. 162 00:08:59,300 --> 00:09:02,110 [no audio] 163 00:09:02,100 --> 00:09:06,410 Just assume that there is some institute, 164 00:09:06,400 --> 00:09:08,700 right, and it is going to give some training. 165 00:09:10,100 --> 00:09:12,800 And just assume that there are four members, they are interested 166 00:09:12,800 --> 00:09:15,300 to join in this institute for some courses. 167 00:09:15,300 --> 00:09:17,410 [no audio] 168 00:09:17,400 --> 00:09:20,710 Right. Whenever these four members are ready to join, 169 00:09:20,700 --> 00:09:26,000 then this institute will give some forms to collect the data, 170 00:09:26,000 --> 00:09:30,700 information about these four students. So, what they will do? 171 00:09:30,700 --> 00:09:34,200 Let's say this is student 1, student 2, 172 00:09:34,200 --> 00:09:39,000 and student 3, then student 4. Then they will give you a form 173 00:09:39,000 --> 00:09:42,600 for this. They are going to give one form for student 1, 174 00:09:42,600 --> 00:09:45,400 student 2 and student 3, then student 4. 175 00:09:45,400 --> 00:09:49,600 Then student 1 will fill the data here, student 2 fill the data here, 176 00:09:49,600 --> 00:09:52,400 student 3 fill the data here, student 4 fill the data here. 177 00:09:52,400 --> 00:09:54,900 [no audio] 178 00:09:54,900 --> 00:09:57,000 But if you observe here, actually 179 00:09:57,000 --> 00:09:58,700 they're having one original template. 180 00:09:59,300 --> 00:10:01,000 They're having one original template. 181 00:10:01,400 --> 00:10:04,700 So, from this template, they're taking a Xerox copy or printout, 182 00:10:04,700 --> 00:10:06,200 and that printout they're sharing 183 00:10:07,800 --> 00:10:10,300 so that the work is easy for this institute. 184 00:10:10,300 --> 00:10:12,200 [no audio] 185 00:10:12,200 --> 00:10:17,910 Now, student 1 fills the data like name, age, address, and interested course. 186 00:10:17,900 --> 00:10:21,800 So, in template, if you have like "Fill the name" here, then "age" here, 187 00:10:21,800 --> 00:10:25,700 then suppose "address", then "interested courses". 188 00:10:26,900 --> 00:10:28,400 Just assume that there are 189 00:10:28,400 --> 00:10:30,200 [no audio] 190 00:10:30,200 --> 00:10:31,800 predefined template is there. 191 00:10:31,800 --> 00:10:34,900 I am giving this template to each and every one 192 00:10:34,900 --> 00:10:38,310 so that I can get the data of these four students very easily. 193 00:10:38,300 --> 00:10:40,700 Suppose if I give an empty form, 194 00:10:40,700 --> 00:10:44,400 then the institute guy has to tell, please fill your name, age, 195 00:10:44,400 --> 00:10:48,000 role number, something like address and interested courses. 196 00:10:48,700 --> 00:10:52,700 But instead of that if the institute guy has some template, 197 00:10:52,700 --> 00:10:55,432 then it is very easy to collect data about students. 198 00:10:55,422 --> 00:10:57,500 [no audio] 199 00:10:57,500 --> 00:11:04,300 Right. So, now that template is called simply blueprint. 200 00:11:04,300 --> 00:11:08,200 So from the template, we are getting the information about your students. 201 00:11:08,200 --> 00:11:13,300 Not only these four students, suppose tomorrow 100 members 202 00:11:13,300 --> 00:11:15,800 are ready to join, then what these guys will do, 203 00:11:15,800 --> 00:11:19,100 the institute guys will do? Simply they will take 100 printouts 204 00:11:19,100 --> 00:11:22,700 of the template, whatever they are having, and these 100 templates 205 00:11:22,700 --> 00:11:24,800 they're going to distribute it for each and every one, 206 00:11:24,800 --> 00:11:28,600 so that they can collect the information about 100 students very easily. 207 00:11:28,600 --> 00:11:31,000 [no audio] 208 00:11:31,000 --> 00:11:36,800 Right. Now in our OOPS concept, template is nothing but a class. 209 00:11:38,100 --> 00:11:41,900 Template is nothing but a class. From the template you can 210 00:11:41,900 --> 00:11:43,800 create any number of objects. 211 00:11:43,800 --> 00:11:45,700 [no audio] 212 00:11:45,700 --> 00:11:50,300 From the template, you can create any number of objects very easily. 213 00:11:51,300 --> 00:11:54,600 Right. Now, I will explain this with a simple example 214 00:11:54,600 --> 00:11:57,800 so that you can get an idea on OOPS concept. Just wait. 215 00:11:59,400 --> 00:12:03,700 One more thing, finally you can say that OOPS is a concept 216 00:12:03,700 --> 00:12:07,100 where characteristics and functions of real-life 217 00:12:07,100 --> 00:12:10,600 object is packaged as a single entity in the code. 218 00:12:12,100 --> 00:12:14,310 Just now we have seen previously, right, 219 00:12:14,300 --> 00:12:16,110 I mean to group related functions. 220 00:12:16,100 --> 00:12:20,641 We are giving some name for functions or simply we are 221 00:12:20,600 --> 00:12:23,300 grouping our functions under one name, 222 00:12:24,900 --> 00:12:29,910 so that there is an advantage while executing your code, right? 223 00:12:29,900 --> 00:12:37,300 See, just assumed that. Let me give a name as, I mean, script name 224 00:12:37,300 --> 00:12:39,300 'working_with_oops.py'. 225 00:12:41,000 --> 00:12:43,300 Just assume that guys. Just assume that 226 00:12:43,300 --> 00:12:46,973 on my host, there are two Apaches running. 227 00:12:46,973 --> 00:12:48,600 [no audio] 228 00:12:48,600 --> 00:12:50,800 Maybe any number of Apaches, no problem. 229 00:12:50,800 --> 00:12:54,810 But initially just to give some idea 230 00:12:54,800 --> 00:12:56,810 I am assuming that on my server 231 00:12:56,800 --> 00:12:58,500 there are two Apaches running. 232 00:12:59,800 --> 00:13:03,410 Just simply assume that. So if two Apaches are running, 233 00:13:03,400 --> 00:13:06,900 if you want to implement a code you need to create two objects. 234 00:13:08,400 --> 00:13:11,500 So if you observe, if you, previously we have seen right, 235 00:13:11,500 --> 00:13:13,800 how we are creating objects? From template. 236 00:13:15,000 --> 00:13:17,300 From template. See that? 237 00:13:18,200 --> 00:13:21,110 So guys, whenever if you are writing a code in terms of OOPS, 238 00:13:21,100 --> 00:13:24,000 and one more thing, basically this OOPS concept is very, 239 00:13:24,000 --> 00:13:27,300 very important for application development or development side. 240 00:13:27,300 --> 00:13:28,300 For automation side, 241 00:13:28,300 --> 00:13:31,400 you can write your code without OOPS concept also, 242 00:13:31,400 --> 00:13:35,100 but if you go with OOPS concept, then you can write your code, 243 00:13:35,100 --> 00:13:37,000 I mean effective code you can write. 244 00:13:38,400 --> 00:13:39,400 Right. Fine. 245 00:13:40,300 --> 00:13:44,800 So guys what I am saying is, just assume that on your server 246 00:13:44,800 --> 00:13:48,200 two Apaches is running, let's say 'tomcat'. Anything you can take. 247 00:13:48,200 --> 00:13:53,110 Let's say I'm taking in this way. In my code two 'tomcats' are running. 248 00:13:53,100 --> 00:13:55,900 Right. See, how I am going to implement my code. 249 00:13:56,900 --> 00:14:02,810 So suppose if your server is Unix-box, then I can say 'bin/python', 250 00:14:02,800 --> 00:14:04,929 then I can start my code in this way, right? 251 00:14:04,929 --> 00:14:07,600 [no audio] 252 00:14:07,600 --> 00:14:11,600 You know, what is the usage of this, '__name__', '__main__'. 253 00:14:11,600 --> 00:14:15,000 [no audio] 254 00:14:15,000 --> 00:14:18,000 Right. Then 'def main()'. That's it. 255 00:14:19,500 --> 00:14:23,000 Now let's say I have suppose 'tomcat7', somewhere 256 00:14:23,000 --> 00:14:27,700 in my location 'home', let's say some, 257 00:14:27,700 --> 00:14:32,300 '/Automation/user', under that we have 'tomcat7', under that 258 00:14:32,300 --> 00:14:35,000 you have some 'conf' directory, 259 00:14:35,000 --> 00:14:38,000 under that, you have some 'server.xml' file. 260 00:14:38,000 --> 00:14:42,000 So why I'm taking 'server.xml' means, if we go with the 'tomcat' 261 00:14:42,000 --> 00:14:44,400 the main configuration file is 'server.xml'. 262 00:14:44,400 --> 00:14:48,500 The same way, just assume that I'm having one more 'tomcat' on my server. 263 00:14:48,500 --> 00:14:50,400 [no audio] 264 00:14:50,400 --> 00:14:53,900 Right. So same values but except 265 00:14:53,900 --> 00:14:56,600 [no audio] 266 00:14:56,600 --> 00:14:57,900 7 this is 9. 267 00:14:59,100 --> 00:15:02,200 So guys while going forward we can also write, 268 00:15:02,200 --> 00:15:05,910 we will also write a code automatically to identify how many 269 00:15:05,900 --> 00:15:07,710 'tomcats' are running on your host. 270 00:15:07,700 --> 00:15:10,910 But for time being I am taking two 'tomcats'. Just I'm assuming, 271 00:15:10,900 --> 00:15:13,410 on my server two 'tomcats' are running. That's fine. 272 00:15:13,400 --> 00:15:15,300 [no audio] 273 00:15:15,300 --> 00:15:16,800 Now actually my intention is, 274 00:15:18,300 --> 00:15:19,400 I have to write a logic 275 00:15:20,000 --> 00:15:24,800 I have to write a logic just to display 'tomcat' configuration file, 276 00:15:24,800 --> 00:15:25,900 and 'tomcat' home. 277 00:15:26,800 --> 00:15:29,552 So already I have taken 'tomcat' configuration file. This is. 278 00:15:29,500 --> 00:15:31,800 [no audio] 279 00:15:31,800 --> 00:15:36,400 Okay. And if you know about 'tomcat', this is called simply 280 00:15:36,400 --> 00:15:38,810 'tomcat' 'home'. Only up to this path 281 00:15:38,800 --> 00:15:41,600 we can say that is 'tomcat' 'home', because under this we are having 282 00:15:41,600 --> 00:15:45,500 every file, I mean the files which are related to your 'tomcat'. 283 00:15:45,500 --> 00:15:47,800 So for 'tomcat7' this is the 'home'. 284 00:15:47,800 --> 00:15:49,400 For 'tomcat9' this is the 'home'. 285 00:15:49,800 --> 00:15:55,400 Now my requirement is, simply I need to display 'tomcat7' config file, 286 00:15:55,400 --> 00:16:01,100 'tomcat9' config file, and 'tomcat7' home, 'tomcat9' home. 287 00:16:01,100 --> 00:16:04,400 Right. Directly I can display, but I want to implement this code first 288 00:16:04,400 --> 00:16:05,800 in terms of functions, 289 00:16:05,800 --> 00:16:09,000 then I will try to convert in terms of OOPS, so that you will get an idea. 290 00:16:10,400 --> 00:16:12,110 Okay. So just wait. 291 00:16:12,100 --> 00:16:14,900 So what I am doing is 'tomcat7_details()'. 292 00:16:14,900 --> 00:16:18,110 [no audio] 293 00:16:18,100 --> 00:16:19,700 Otherwise what I will do is, 294 00:16:20,700 --> 00:16:25,400 'get_details_for_each_tomcat()', 295 00:16:25,400 --> 00:16:27,200 [no audio] 296 00:16:27,200 --> 00:16:28,200 'each_tomcat' 297 00:16:28,400 --> 00:16:30,500 Let me pass 'tomcat7' here. 298 00:16:31,000 --> 00:16:36,900 The same way I need to get details for each 'tomcat', 'tomcat 9'. That's it. 299 00:16:37,600 --> 00:16:40,900 Right. So finally, I am doing 'return None'. 300 00:16:40,982 --> 00:16:42,700 [No audio] 301 00:16:42,700 --> 00:16:44,100 Now here I'm writing a function. 302 00:16:45,100 --> 00:16:47,700 So I need an 'os' module here. Let me import that. 303 00:16:47,700 --> 00:16:50,100 So after that what I am doing is, I am defining a function 304 00:16:50,100 --> 00:16:51,300 called 'get', 305 00:16:53,100 --> 00:16:54,300 Guys let me write. 306 00:16:54,300 --> 00:16:59,700 [no audio] 307 00:16:59,700 --> 00:17:01,000 Let me take function name. 308 00:17:01,000 --> 00:17:05,400 [no audio] 309 00:17:05,400 --> 00:17:07,810 And whatever you're passing, that is configuration file. 310 00:17:07,800 --> 00:17:09,500 So that is like 'server_xml'. 311 00:17:09,500 --> 00:17:11,200 I am taking 'server_xml'. 312 00:17:12,000 --> 00:17:13,000 That's fine. 313 00:17:13,200 --> 00:17:15,900 So now what I am doing is, first of all I am finding 314 00:17:15,900 --> 00:17:17,900 [no audio] 315 00:17:17,900 --> 00:17:22,200 'tomcat' configuration file, 'tcf' variable. It is nothing but directly 316 00:17:22,200 --> 00:17:25,800 you can assume your 'server.xml'. Then I am finding 'tomcat' 'home'. 317 00:17:25,800 --> 00:17:31,599 It is nothing but 'os.path.dirname(server_xml)' 318 00:17:31,599 --> 00:17:34,599 file. But if I do this operation, you are 319 00:17:34,599 --> 00:17:39,000 going to get up to 'conf'. But I need up to 'tomcat7'. 320 00:17:40,200 --> 00:17:43,599 If you come back two levels back in configuration file, then 321 00:17:43,599 --> 00:17:45,000 you are going to get 'tomcat', 'home'. 322 00:17:45,400 --> 00:17:49,300 So I need to apply one more time 'os.path.dirname'. 323 00:17:49,300 --> 00:17:51,800 Already we've done this in our previous videos. 324 00:17:53,000 --> 00:17:55,000 That's it. Right. 325 00:17:55,400 --> 00:17:58,900 And here if you want to display your information, directly you can display. 326 00:17:58,900 --> 00:18:07,468 So I am writing, "The tomcat config file is". 327 00:18:07,400 --> 00:18:12,510 So, simply here, I am writing 'tcf', 'tomcat' configuration file. 328 00:18:12,500 --> 00:18:15,700 And then I need to display 'tomcat' 'home' as well, right? 329 00:18:16,200 --> 00:18:19,000 So "The tomcat home is". 330 00:18:19,000 --> 00:18:22,400 So here I am displaying 'tomcat' 'home'. That's it. 331 00:18:22,400 --> 00:18:26,110 So finally I am returning with "None" value. That's it. 332 00:18:26,100 --> 00:18:28,893 Let me run this code. What happened? 333 00:18:28,883 --> 00:18:31,100 [no audio] 334 00:18:31,100 --> 00:18:33,800 no attribute 'dirname', directory name. 335 00:18:33,800 --> 00:18:37,500 [no audio] 336 00:18:37,500 --> 00:18:38,600 I imported right. 337 00:18:38,600 --> 00:18:46,600 [no audio] 338 00:18:46,600 --> 00:18:47,600 'ntpath' 339 00:18:47,600 --> 00:18:50,400 [no audio] 340 00:18:50,400 --> 00:18:51,500 Where is that error? 341 00:18:51,500 --> 00:19:00,000 [no audio] 342 00:19:00,000 --> 00:19:01,210 That's fine. 343 00:19:01,200 --> 00:19:05,110 'os.path.dirname', 'os.path.dirname'. 344 00:19:05,100 --> 00:19:23,700 [no audio] 345 00:19:23,700 --> 00:19:25,000 What happened here? 346 00:19:26,000 --> 00:19:28,400 Let me enter into my 'python', 'import os'. 347 00:19:28,400 --> 00:19:31,100 [no audio] 348 00:19:31,100 --> 00:19:34,010 'dir(os.path)' 349 00:19:34,000 --> 00:19:35,910 Let me write, and see the options. 350 00:19:35,900 --> 00:19:39,100 [no audio] 351 00:19:39,100 --> 00:19:41,500 It is there no, 'dirname'. 352 00:19:43,100 --> 00:19:49,000 Did I make spelling mistake? No, 'os.path.dirname'. Oh, sorry. 353 00:19:49,000 --> 00:19:50,600 Here, spelling mistake. 354 00:19:51,800 --> 00:19:52,800 That's fine. 355 00:19:53,300 --> 00:19:54,300 Now see the result. 356 00:19:55,800 --> 00:19:58,600 You are getting the output for your first 'tomcat'' 357 00:19:58,600 --> 00:20:02,633 I mean, 'tomcat7' and 'tomcat9'. But here, if you observe 358 00:20:03,400 --> 00:20:04,400 in the same function 359 00:20:04,400 --> 00:20:07,400 I am finding my configuration file and 'tomcat' home, 360 00:20:07,400 --> 00:20:10,829 and also I am displaying. But I want to display the information 361 00:20:10,829 --> 00:20:13,724 using other function. Then what I am doing is, 362 00:20:13,700 --> 00:20:17,300 [no audio] 363 00:20:17,300 --> 00:20:21,600 then I am writing 'display_details'. 364 00:20:21,600 --> 00:20:24,400 [no audio] 365 00:20:24,400 --> 00:20:25,400 That's it. 366 00:20:25,900 --> 00:20:28,800 Okay, now if I run this, anyway you're not calling. 367 00:20:28,800 --> 00:20:29,800 Let me call that. 368 00:20:31,100 --> 00:20:34,300 So after getting details for 'tomcat7', I am 369 00:20:34,300 --> 00:20:36,500 trying to display the details for that. 370 00:20:36,500 --> 00:20:40,400 So simply, 'display_details()'. On 'tomcat7' 371 00:20:41,700 --> 00:20:45,200 'display_details()'. But if I run this you are going to get an error 372 00:20:45,200 --> 00:20:47,400 that is, 'tcf' is not defined. 373 00:20:47,400 --> 00:20:51,000 See you know, in your functions concept be clear. 374 00:20:51,000 --> 00:20:54,200 It is very, very important. In your normal functions concept 375 00:20:54,200 --> 00:20:57,800 if you define any variable inside of one function, then you 376 00:20:57,800 --> 00:21:00,810 cannot access that inside of other function. 377 00:21:00,800 --> 00:21:03,910 The reason is, whenever you define any variable, 378 00:21:03,900 --> 00:21:06,000 by default that is local to that function. 379 00:21:06,000 --> 00:21:09,500 Now, I want to access in this function, then what I have to do? 380 00:21:09,500 --> 00:21:13,400 I need to make it 'global'. 381 00:21:13,400 --> 00:21:18,300 Your two variables 'tcf' and 'th', I need to make it as a global. 382 00:21:18,300 --> 00:21:20,100 Now, I am able to get your values. 383 00:21:20,100 --> 00:21:22,700 [no audio] 384 00:21:22,700 --> 00:21:24,000 Right. That's fine. 385 00:21:25,000 --> 00:21:28,100 Now what I am doing is, I am removing these two functions 386 00:21:28,100 --> 00:21:29,700 to display your details 387 00:21:29,700 --> 00:21:33,200 First I am calling your 'get_details_for_each_tomcat()' 388 00:21:33,200 --> 00:21:35,100 - 'tomcat7' and 'tomcat9'. 389 00:21:35,100 --> 00:21:37,300 So, after this I am calling 'display_details()'. 390 00:21:37,300 --> 00:21:39,100 [no audio] 391 00:21:39,100 --> 00:21:40,100 I am calling two times. 392 00:21:40,100 --> 00:21:42,100 [no audio] 393 00:21:42,100 --> 00:21:43,910 Now, what is the result you're going to get? 394 00:21:43,900 --> 00:21:46,800 Both the times you are going to get 'tomcat9' details. 395 00:21:46,800 --> 00:21:48,200 Then where is 'tomcat7'? 396 00:21:49,900 --> 00:21:53,200 So, this is the problem with your normal functions concept. 397 00:21:53,283 --> 00:21:55,200 [no audio] 398 00:21:55,200 --> 00:21:58,700 See, whenever if you call, if you call, 399 00:22:00,300 --> 00:22:04,800 your 'get_details' for 'tomcat7', you're coming here 400 00:22:04,800 --> 00:22:07,000 and you're getting your variables called, 401 00:22:07,000 --> 00:22:09,000 variables called 'tcf' and 'th'. 402 00:22:10,000 --> 00:22:14,200 Because of 17th line you're going to execute this function. 403 00:22:14,200 --> 00:22:19,400 And after executing this function in your variables called 'tcf' and 'th', 404 00:22:19,400 --> 00:22:22,000 you are having values for 'tomcat7'. 405 00:22:22,000 --> 00:22:25,400 That's fine. Then immediately you're calling 'tomcat9' also. 406 00:22:25,400 --> 00:22:28,400 Then whenever if you call, then you are coming to same function 407 00:22:28,400 --> 00:22:31,600 and you are going to overwrite or rewrite, new values 408 00:22:31,600 --> 00:22:33,100 for your 'tcf' and 'th'. 409 00:22:33,100 --> 00:22:35,100 [no audio] 410 00:22:35,100 --> 00:22:40,900 Right. Then your old values gone. 'tomcat7' information gone. 411 00:22:40,965 --> 00:22:43,100 [no audio] 412 00:22:43,100 --> 00:22:48,100 Then, to capture your 'tomcat7' details before calling 'tomcat9', 413 00:22:48,100 --> 00:22:51,200 you have to return your 'tomcat7' details with the help 414 00:22:51,200 --> 00:22:55,100 of 'return tcf,th'. And that values we can assign into some 415 00:22:55,100 --> 00:22:56,800 list or some variables here. 416 00:22:56,800 --> 00:22:59,510 I mean, let me write in this way 417 00:22:59,500 --> 00:23:01,110 so that you will get an idea. 418 00:23:01,100 --> 00:23:08,700 So what I am doing is, 'tomcat7_tcf', 419 00:23:05,500 --> 00:23:40,810 [no audio] 420 00:23:08,700 --> 00:23:18,600 and 'tomcat7_th'. Then I need to return here, right, 421 00:23:18,600 --> 00:23:22,300 'tcf' and then 'th'. But I don't want to do this thing. 422 00:23:23,300 --> 00:23:26,700 I want to capture my values without returning in my code. 423 00:23:27,400 --> 00:23:29,900 Then it is not possible with your normal functions concept. 424 00:23:29,900 --> 00:23:32,200 [no audio] 425 00:23:32,200 --> 00:23:36,410 Then, it is possible with your OOPS concept, right. 426 00:23:36,400 --> 00:23:39,400 Let me write one more program with OOPS concept 427 00:23:39,400 --> 00:23:40,800 so that you will get now an idea 428 00:23:40,800 --> 00:23:45,300 [no audio] 429 00:23:45,300 --> 00:23:50,800 So, 'with_oops.py'. Guys be clear. 430 00:23:52,000 --> 00:23:55,200 First thing, anyway, let me start in this way. 431 00:23:55,200 --> 00:23:56,200 This is common. 432 00:23:56,200 --> 00:23:58,000 [no audio] 433 00:23:58,000 --> 00:23:59,000 Sorry, not that. 434 00:23:59,000 --> 00:24:03,500 [no audio] 435 00:24:03,500 --> 00:24:05,564 Then I am defining 'main()' function. 436 00:24:05,564 --> 00:24:07,600 [no audio] 437 00:24:07,600 --> 00:24:12,000 That's fine. And inside of that, first of all, I am taking configuration files 438 00:24:12,000 --> 00:24:15,200 of 'tomcat7' and 'tomcat9'. Okay. 439 00:24:15,200 --> 00:24:18,700 [no audio] 440 00:24:18,700 --> 00:24:22,900 Or you can also take name like 'tomcat7_cf', 441 00:24:22,900 --> 00:24:27,410 'tomcat9_cf'. No problem. Any variable. Just 442 00:24:27,400 --> 00:24:29,500 I have taken previously 'tomcat7', 'tomcat9', 443 00:24:29,500 --> 00:24:33,800 but I am taking the 'tomcat7_cf' and 'tomcat_9cf'. No problem. 444 00:24:34,400 --> 00:24:35,400 That's fine. 445 00:24:36,100 --> 00:24:40,110 Now let me write simply, 'return None'. 446 00:24:40,100 --> 00:24:43,000 So this is just like your functions. Now in this I want to 447 00:24:43,000 --> 00:24:44,300 include OOPS concept. 448 00:24:45,100 --> 00:24:47,200 So guys at the end of this explanation 449 00:24:47,200 --> 00:24:49,600 you will come to know the usage of OOPS. 450 00:24:49,600 --> 00:24:53,200 And one more thing, whenever if you want to write OOPs concept, 451 00:24:53,200 --> 00:24:56,700 in your code, first thing is you need to define a template. 452 00:24:57,700 --> 00:24:59,800 So, if you want to define any template, you have to take a 453 00:24:59,800 --> 00:25:00,800 keyword called 'class'. 454 00:25:01,900 --> 00:25:03,400 So, what is our concept? 455 00:25:03,400 --> 00:25:08,100 On 'tomcat' we're working. Take any name for your template. That's it. 456 00:25:08,800 --> 00:25:10,900 And whenever if you're defining a template name, 457 00:25:10,900 --> 00:25:13,200 just start your name with capital letter. 458 00:25:14,200 --> 00:25:18,510 That is optional, but it's good to start with capital letters. That's it. 459 00:25:18,500 --> 00:25:20,400 So guys, basically you need to define a template 460 00:25:20,400 --> 00:25:22,800 before going to use OOPS concept in your code. 461 00:25:23,400 --> 00:25:27,100 But instead of calling it as a template, just call it as a 462 00:25:27,100 --> 00:25:28,910 class, defining a class. 463 00:25:28,900 --> 00:25:31,300 But in your mind just assume that defining a class is nothing 464 00:25:31,300 --> 00:25:34,600 but preparing some format, preparing some template. 465 00:25:35,300 --> 00:25:37,100 That's it. Right. 466 00:25:37,600 --> 00:25:41,700 So now one more thing, we know that creating template is nothing 467 00:25:41,700 --> 00:25:44,200 but grouping some related functions into that. 468 00:25:44,200 --> 00:25:46,000 [no audio] 469 00:25:46,000 --> 00:25:48,200 To group related functions we are using OOPS concept. 470 00:25:48,200 --> 00:25:51,500 To group related functions we are creating template. 471 00:25:51,500 --> 00:25:54,800 To group related functions we are creating class. 472 00:25:55,600 --> 00:25:59,500 So now basically in your previous code what are the functions you need? 473 00:26:00,500 --> 00:26:02,748 'get_details_for_each_tomcat()', 474 00:26:02,700 --> 00:26:07,800 and one more thing is, let me take only functions names first. 475 00:26:09,000 --> 00:26:12,510 One function is, this one, right? 476 00:26:12,500 --> 00:26:17,200 And second function is, 'display_details()'. 477 00:26:18,000 --> 00:26:19,510 So be clear. 478 00:26:19,500 --> 00:26:22,300 Now you're getting clarity on your OOPS. 479 00:26:23,000 --> 00:26:24,000 That's fine. 480 00:26:24,500 --> 00:26:29,200 So guys one more thing. Whenever, if you define any function inside of a class, 481 00:26:29,200 --> 00:26:31,600 then you have to say that that is a method, 482 00:26:31,600 --> 00:26:36,000 not a function. Of course, both are same except one extra keyword. 483 00:26:36,000 --> 00:26:39,910 See whenever you're defining a function in your 484 00:26:39,900 --> 00:26:42,900 class, then you have to say it as a method and you have to 485 00:26:42,900 --> 00:26:46,700 write one default argument at the very first always that has a 'self'. 486 00:26:47,400 --> 00:26:50,200 See in your previous code, your function is taking 487 00:26:50,200 --> 00:26:51,700 only one argument. Here 488 00:26:51,700 --> 00:26:54,600 also it is taking only one argument. Forget about this. But 489 00:26:54,600 --> 00:26:56,900 you have to write it. Why? You will get clarity. 490 00:26:57,900 --> 00:27:00,500 The same way 'display' function is not taking 491 00:27:00,500 --> 00:27:01,800 anything in your previous code no. 492 00:27:02,800 --> 00:27:05,100 Now here also it is not taking anything, but you have to write 'self' 493 00:27:05,100 --> 00:27:07,600 first. Write 'self' and forget about it. 494 00:27:08,000 --> 00:27:10,200 Assume that there is no extra keyword here. 495 00:27:10,200 --> 00:27:13,000 'self' and 'self', here and here. That's it. 496 00:27:14,400 --> 00:27:17,700 Okay, but there is a purpose for 'self'. Not only 'self', you can 497 00:27:17,700 --> 00:27:19,900 write any keyword as a first argument, and you have to use 498 00:27:19,900 --> 00:27:21,910 that same argument in your code. 499 00:27:21,900 --> 00:27:27,100 I can write simply my name, but universally all are following 'self' 500 00:27:27,100 --> 00:27:33,300 as the first argument by default, in your method of a class. That's fine. 501 00:27:33,900 --> 00:27:36,200 Now, go to your previous code. 502 00:27:37,100 --> 00:27:41,371 So now here we don't bother, about global or like. 503 00:27:41,300 --> 00:27:45,400 Okay. So I need to define our very first variable called 'tcf'. 504 00:27:46,900 --> 00:27:48,800 Let me copy these two variables. 505 00:27:48,800 --> 00:27:58,810 [no audio] 506 00:27:58,800 --> 00:28:01,400 So, this is the normal function. Under normal function 507 00:28:01,400 --> 00:28:03,300 generally we are defining variables in this way. 508 00:28:03,700 --> 00:28:08,110 But whenever if you define variables inside of a method 509 00:28:08,100 --> 00:28:11,710 always you have to write your variable with 'self.tcf', 510 00:28:11,700 --> 00:28:13,000 I mean you're required variable. 511 00:28:13,000 --> 00:28:14,800 [no audio] 512 00:28:14,800 --> 00:28:20,500 'self.th'. Why? Again, you will come to know. Just wait. 513 00:28:21,900 --> 00:28:24,200 Okay. See normally in your functions if you want to define 514 00:28:24,200 --> 00:28:27,800 any variable, you're writing x=2, y=3, something like that. 515 00:28:27,800 --> 00:28:32,000 But here just assume that instead of writing, 'x', 'self.x', 'self.y'. That's it. 516 00:28:33,400 --> 00:28:35,418 Right. And finally write, 'return None'. 517 00:28:35,400 --> 00:28:39,100 [no audio] 518 00:28:39,100 --> 00:28:42,900 Then, 'display' function. So in 'display_details()' you are having 519 00:28:42,900 --> 00:28:45,200 this thing no. Let me copy the same lines. 520 00:28:45,202 --> 00:28:51,910 [no audio] 521 00:28:51,900 --> 00:28:53,400 Let me arrange indentations. 522 00:28:53,400 --> 00:28:56,800 [no audio] 523 00:28:56,800 --> 00:28:59,700 So whenever if you want to use your variables inside of methods, 524 00:28:59,700 --> 00:29:01,810 always you have 'self.'. 525 00:29:01,800 --> 00:29:03,500 That's why you have to write here 'self.'. 526 00:29:04,700 --> 00:29:05,700 'self.'. 527 00:29:05,700 --> 00:29:07,700 [no audio] 528 00:29:07,700 --> 00:29:08,700 That's it. 529 00:29:09,600 --> 00:29:11,200 Okay. That's fine. 530 00:29:11,200 --> 00:29:14,200 Now, be clear. Just now we created a template. 531 00:29:14,200 --> 00:29:16,100 [no audio] 532 00:29:16,100 --> 00:29:19,110 Right. Like institute is having a template, and whenever 533 00:29:19,100 --> 00:29:21,800 students are ready to take some courses from institute, 534 00:29:21,800 --> 00:29:24,100 institute is giving some template to each and every student. 535 00:29:24,100 --> 00:29:27,400 So, student is going to fill their data into that template. 536 00:29:28,400 --> 00:29:30,700 Now, if you observe in our code we have two 'tomcats'. 537 00:29:30,700 --> 00:29:33,800 Assume that these 'tomcats' are like two students, 538 00:29:34,700 --> 00:29:36,800 and this is like a form for institute. 539 00:29:36,800 --> 00:29:38,800 Now, we need to pass this, 540 00:29:38,800 --> 00:29:42,110 we need to give the copy of this 'tomcat' 541 00:29:42,100 --> 00:29:45,500 template to 'tomcat7', as well as 'tomcat9'. 542 00:29:45,500 --> 00:29:48,900 That's why, see that? I am going to create an object. 543 00:29:49,900 --> 00:29:54,900 I am going to create objects, even forget about your configuration files first. 544 00:29:54,900 --> 00:29:58,500 [no audio] 545 00:29:58,500 --> 00:30:03,410 So, we are assuming that on our server we are having two 'tomcats'. 546 00:30:03,400 --> 00:30:08,110 That's why we need to get two templates into your hand. 547 00:30:08,100 --> 00:30:11,900 I mean, if there are two 'tomcats', we need to create two objects. 548 00:30:13,300 --> 00:30:17,700 How to create an object? Very simple. So we are having 'tomcat7', 549 00:30:17,700 --> 00:30:23,600 right, and then 'tomcat9'. Then first take your required object names. 550 00:30:23,600 --> 00:30:25,500 'tomcat7='. 551 00:30:27,000 --> 00:30:29,600 Guys, to create an object 552 00:30:29,800 --> 00:30:33,010 what we have to do is, we have to take a Xerox copy of template. 553 00:30:33,000 --> 00:30:36,510 So, what is our template? This is our template. 554 00:30:36,500 --> 00:30:39,610 So, what is the name for the template? 'tomcat'. That's it. 555 00:30:39,600 --> 00:30:43,210 Simply take here 'tomcat', but you have to write parenthesis here. 556 00:30:43,200 --> 00:30:48,410 Then create an object for 'tomcat9'. 'Tomcat()'. That's it. 557 00:30:48,400 --> 00:30:50,600 So same Xerox copy of this template 558 00:30:50,600 --> 00:30:53,600 we have given for 'tomcat7' and 'tomcat9'. 559 00:30:54,600 --> 00:30:59,800 'tomcat7' and 'tomcat9'. As of now, we have given Xerox copies to the students. 560 00:30:59,800 --> 00:31:03,000 Now, if students fills the data in the template, 561 00:31:03,000 --> 00:31:08,100 then we are having information about that student in the template, right? 562 00:31:08,100 --> 00:31:10,900 So as of now, we are not creating an object. Simply 563 00:31:10,900 --> 00:31:15,500 we have given the template copy to two objects, 'tomcat7' and 564 00:31:15,500 --> 00:31:18,600 'tomcat9'. Now actually, if you want to create an object, 565 00:31:18,600 --> 00:31:20,300 you need to fill the data. 566 00:31:20,300 --> 00:31:22,400 Fill the data means, you have to call at least 567 00:31:22,400 --> 00:31:24,400 one method from your template. 568 00:31:25,100 --> 00:31:26,700 If you want to call all methods, no problem. 569 00:31:26,700 --> 00:31:28,000 At least you have to call one method, 570 00:31:28,000 --> 00:31:30,610 then we can say that object has been created. 571 00:31:31,500 --> 00:31:33,900 Now, 'tomcat7'. 572 00:31:34,900 --> 00:31:38,700 '.'. See guys if you want to call any method 573 00:31:38,700 --> 00:31:42,600 inside of your object you need to use "." 574 00:31:44,000 --> 00:31:47,900 First thing, be clear. This entire template is there in this 575 00:31:47,900 --> 00:31:49,800 'tomcat7' and 'tomcat9'. 576 00:31:51,000 --> 00:31:53,700 Right. So whenever if you are working with 'tomcat7' you have to 577 00:31:53,700 --> 00:31:56,000 assume that this entire thing is for 'tomcat7'. 578 00:31:56,000 --> 00:31:58,900 And whenever if you are working with 'tomcat9', then you have to 579 00:31:58,900 --> 00:32:00,900 assume that this entire thing is for 'tomcat9'. 580 00:32:00,900 --> 00:32:03,010 [no audio] 581 00:32:03,000 --> 00:32:07,900 Observe that. I want to get my, for 'tomcat7' 582 00:32:07,900 --> 00:32:11,310 I need to get configuration file, and 'tomcat' home. 583 00:32:11,300 --> 00:32:17,710 Then what I have to do is, I need to call this function, method just by passing 584 00:32:17,700 --> 00:32:21,700 [no audio] 585 00:32:21,700 --> 00:32:25,200 this 'conf' because that is taking, configuration file, right? 586 00:32:25,200 --> 00:32:27,910 [no audio] 587 00:32:27,900 --> 00:32:30,200 Now whenever if you call in this way, 588 00:32:30,200 --> 00:32:35,400 Python is going to convert internally this as, be clear, be clear. 589 00:32:35,400 --> 00:32:42,900 [no audio] 590 00:32:42,900 --> 00:32:44,310 Don't write this in your code. 591 00:32:44,300 --> 00:32:47,800 You will get an error. But python will convert that internally in this way. 592 00:32:47,800 --> 00:32:50,300 [no audio] 593 00:32:50,300 --> 00:32:51,500 'tomcat7' 594 00:32:51,500 --> 00:32:54,800 [no audio] 595 00:32:54,800 --> 00:32:56,600 That's it. Let me enable it. 596 00:32:56,600 --> 00:33:00,300 Actually, you should not write. So the same function, this line, 597 00:33:00,300 --> 00:33:03,100 this line is going to convert into, in this way. 598 00:33:04,100 --> 00:33:05,800 So whenever if you convert in this way, 599 00:33:05,800 --> 00:33:09,800 now you can assume, whenever if you are calling this method, 600 00:33:10,800 --> 00:33:13,800 right, what is the 'self' value, 601 00:33:15,300 --> 00:33:19,210 'self' is nothing but now 'tomcat7'. 602 00:33:19,200 --> 00:33:24,800 Now in the entire template replace 'self' with 'tomcat7'. Now what 603 00:33:24,800 --> 00:33:27,500 you are doing? 'tomcat7.tcf'. 604 00:33:27,500 --> 00:33:30,000 Of course, that is 'self', but 'self' is 'tomcat7'. 605 00:33:30,600 --> 00:33:32,300 So, 'tomcat7.tcf'. 606 00:33:32,300 --> 00:33:34,610 So, in memory somewhere 607 00:33:34,600 --> 00:33:40,700 your Python is creating 'tomcat7.tcf', 608 00:33:40,700 --> 00:33:43,400 [no audio] 609 00:33:43,400 --> 00:33:48,700 and at the same time 'tomcat7.th'. 610 00:33:50,100 --> 00:33:54,100 Now, two variables dynamically created for your 'tomcat7'. 611 00:33:54,100 --> 00:33:56,500 [no audio] 612 00:33:56,500 --> 00:34:01,700 The same way in case if we called 'tomcat9', for 'tomcat9' also, 613 00:34:01,700 --> 00:34:04,900 your, in memory somewhere, because while calling 614 00:34:04,900 --> 00:34:08,500 from 'tomcat9', while calling 'get_details_for_each_tomcat()' 615 00:34:08,500 --> 00:34:13,000 from 9, 'self' is becoming 9, 'tomcat9'. 616 00:34:13,000 --> 00:34:17,610 That's why, whenever if it is executing this method for 'tomcat9', 617 00:34:17,600 --> 00:34:21,000 again dynamically two variables are created like 618 00:34:21,000 --> 00:34:28,800 'tomcat9.tcf' and 'tomacat9.tf', 619 00:34:28,800 --> 00:34:32,300 'tomcat' home. Sorry, 'th', 'tomcat' home. 620 00:34:33,699 --> 00:34:36,100 But if you observe in your code, we are not having four variables. 621 00:34:36,100 --> 00:34:39,900 We're having only two variables. But while running, separately 622 00:34:39,900 --> 00:34:44,800 your four variables are created. Then how they are going to create? 623 00:34:44,800 --> 00:34:45,800 Just wait. 624 00:34:45,800 --> 00:34:48,000 [no audio] 625 00:34:48,000 --> 00:34:49,000 First, let me write. 626 00:34:50,000 --> 00:34:53,600 Let me call for 'tomcat9' also. 627 00:34:53,600 --> 00:34:58,400 [no audio] 628 00:34:58,400 --> 00:35:01,300 So, while calling from 'tomcat9', configuration file is this one, 629 00:35:01,300 --> 00:35:04,600 and you have to call from 'tomcat9'. That's it. 630 00:35:05,900 --> 00:35:10,699 Okay. But once again, whenever if you call any method from 631 00:35:10,699 --> 00:35:14,110 object, internally your python will convert in this way. 632 00:35:14,100 --> 00:35:18,900 So, while converting in this way by default 'self' keyword is always 633 00:35:18,900 --> 00:35:22,500 pointing to from which object you are calling, 634 00:35:22,500 --> 00:35:25,600 so that separate variables are created, separate variables 635 00:35:25,600 --> 00:35:27,500 are going to be created for each and every object. 636 00:35:27,500 --> 00:35:29,100 Now, there is no overlap. 637 00:35:29,699 --> 00:35:33,000 See previously if you observed your normal functions concept if 638 00:35:33,000 --> 00:35:36,600 you call this 'get_details' for 'tomcat7', you're getting 639 00:35:36,600 --> 00:35:39,300 information in these two variables for 'tomcat7'. 640 00:35:40,300 --> 00:35:45,800 But if you call from 'tomcat9', if you call from 'tomcat9' 641 00:35:45,800 --> 00:35:50,300 then your variables are overwritten with 'tomcat9' data. 642 00:35:50,300 --> 00:35:53,200 'tomcat7' data is going to delete. 643 00:35:54,200 --> 00:35:57,400 But here that is not the case. Whenever if you call from 'tomcat7', 644 00:35:57,400 --> 00:36:00,500 'tomcat7' variables are dynamically creating, 645 00:36:00,500 --> 00:36:02,400 and whenever if you call from 'tomcat9', 646 00:36:02,400 --> 00:36:04,700 'tomcat9' variables are dynamically creating. 647 00:36:04,700 --> 00:36:07,500 [no audio] 648 00:36:07,500 --> 00:36:08,600 Right. Fine. 649 00:36:09,100 --> 00:36:13,610 So guys, now we are saying that 'tomcat7' object has been created, 650 00:36:13,600 --> 00:36:15,200 'tomcat9' has been created, 651 00:36:16,600 --> 00:36:19,500 somewhere in memory, right. See that. 652 00:36:19,500 --> 00:36:23,310 [no audio] 653 00:36:23,300 --> 00:36:26,000 Somewhere in memory 'tomcat', 654 00:36:26,000 --> 00:36:32,000 I'm not writing full 'tomcat', just simply writing 't7' and 't9'. 655 00:36:33,100 --> 00:36:36,500 So, 't7.tcf' variable, 656 00:36:36,500 --> 00:36:40,400 't7.th', 657 00:36:40,400 --> 00:36:47,700 and 't9.tcf', configuration file and 't9.th'. 658 00:36:48,700 --> 00:36:53,900 So, these variables are created, but these variables are there under this name. 659 00:36:53,900 --> 00:36:58,300 So, this is called an object. Under this object, these two variables are packed. 660 00:36:59,800 --> 00:37:02,300 Right. So, if you want to get these variables, always 661 00:37:02,300 --> 00:37:04,800 you have to get 'Tomcat()' object. 662 00:37:04,800 --> 00:37:08,800 So, simply 'tomcat.', 't9.tcf', 't9.th', 663 00:37:08,800 --> 00:37:12,200 or 't7.tcf', 't7.th'. 664 00:37:13,500 --> 00:37:16,100 Right. So here if you observe, dynamically we are 665 00:37:16,100 --> 00:37:17,500 creating our variables. 666 00:37:18,400 --> 00:37:20,700 Right. And see, 667 00:37:22,100 --> 00:37:23,700 and one more thing, very important one. 668 00:37:24,600 --> 00:37:28,310 If you want to access these variables in other function, 669 00:37:28,300 --> 00:37:32,100 in normal functional programming concept, what we are doing? 670 00:37:32,100 --> 00:37:33,900 We are making our variables as global, 671 00:37:34,900 --> 00:37:38,900 but in OOPS concept you can access this variable 672 00:37:38,931 --> 00:37:42,000 inside of other function without 673 00:37:42,000 --> 00:37:45,900 making this as global, because these two methods 674 00:37:45,900 --> 00:37:47,300 we group under 'tomcat'. 675 00:37:47,300 --> 00:37:49,500 [no audio] 676 00:37:49,500 --> 00:37:52,900 That's why one method variables you can access 677 00:37:52,900 --> 00:37:54,600 inside of other method variable. 678 00:37:54,600 --> 00:37:58,010 So, here we are reducing one step, making global. 679 00:37:58,000 --> 00:37:59,400 We are not making global. By default 680 00:37:59,400 --> 00:38:03,410 we can access one variable of one method into another variable. 681 00:38:03,400 --> 00:38:07,110 That's why directly I have done 'self.tcf'. Right. 682 00:38:07,100 --> 00:38:12,200 So, guys now after executing these, I mean from 'tomcat7' this method, 683 00:38:12,200 --> 00:38:14,782 and 'tomcat9' this method, 684 00:38:14,782 --> 00:38:16,400 in memory somewhere 685 00:38:16,400 --> 00:38:21,300 we are creating four variables, two for 'tomcat7' and two for 'tomcat9'. 686 00:38:22,100 --> 00:38:25,110 Right. Be clear, how they are going to create. 687 00:38:25,100 --> 00:38:29,132 So, simply one memory location for 'tomcat7', 688 00:38:29,132 --> 00:38:31,610 and just you have to call this as an object. 689 00:38:31,600 --> 00:38:35,800 And one memory location for 'tomcat9', and this is an object. 690 00:38:35,800 --> 00:38:40,200 And in this we have, 'tcf' variable and 'th' variable. The same way here 691 00:38:40,200 --> 00:38:45,000 also we have 'tcf' variable and 'th' variable. 692 00:38:45,000 --> 00:38:46,910 If I want to get 'th', 693 00:38:46,900 --> 00:38:49,600 I mean 'tomcat' home, 't7.th', 694 00:38:49,600 --> 00:38:54,600 I have to use. See I'm not calling display externally, 695 00:38:54,600 --> 00:38:58,700 outside of your class, inside of my 'main()' function. 696 00:38:59,900 --> 00:39:03,600 Whenever you are in the inside of a class, then only you have to take 'self'. 697 00:39:03,600 --> 00:39:06,100 Be clear. Whenever you are inside of a class, 698 00:39:06,100 --> 00:39:08,100 then only you have to take 'self' keyword. 699 00:39:08,100 --> 00:39:10,200 Whenever if you are in the outside of a class, 700 00:39:10,200 --> 00:39:11,900 you have to take your object name. 701 00:39:11,900 --> 00:39:16,100 So, 'tomcat9'. For 'tomcat9' we have two variables. 702 00:39:16,100 --> 00:39:19,900 What are those two variables? 'tcf' and 'th'. But I want to display them, 703 00:39:19,900 --> 00:39:21,400 then, '.tcf', 704 00:39:21,400 --> 00:39:23,900 [no audio] 705 00:39:23,900 --> 00:39:27,800 then print. '.th'. See the result. 706 00:39:27,800 --> 00:39:29,800 [no audio] 707 00:39:29,800 --> 00:39:31,800 Something wrong. What is that? Let me verify. 708 00:39:31,800 --> 00:39:35,600 [no audio] 709 00:39:35,600 --> 00:39:38,200 'os' is not defined. Yeah, we need to import that 'os'. 710 00:39:38,200 --> 00:39:42,700 [no audio] 711 00:39:42,700 --> 00:39:44,000 Let me 'import os'. 712 00:39:45,700 --> 00:39:47,400 Now run the output. See the result. 713 00:39:47,400 --> 00:39:48,900 You are getting 'tomcat9' details. 714 00:39:50,300 --> 00:39:52,700 Now I can print randomly. 715 00:39:52,700 --> 00:39:58,600 First, I can print 'tomcat9.tcf', then 'tomcat7.th', and then at last 716 00:39:58,600 --> 00:40:04,200 I can print, 'print(tomcat7.tcf)'. 717 00:40:05,300 --> 00:40:07,600 Yes, you can access at any time, randomly 718 00:40:07,600 --> 00:40:08,800 your required variables. 719 00:40:10,100 --> 00:40:13,500 Because somewhere in memory location they're going to create 720 00:40:13,500 --> 00:40:16,010 a new variable for each and every object. 721 00:40:16,000 --> 00:40:17,300 They are not going to overlap. 722 00:40:18,100 --> 00:40:20,000 'tomcat9' is separate memory location, 723 00:40:20,000 --> 00:40:23,700 'tomcat7' object is separate memory location, right? 724 00:40:24,000 --> 00:40:29,300 So, this is the way how we can access your variables outside of a class. 725 00:40:29,300 --> 00:40:33,410 But we already defined a function inside of your class to display your variables. 726 00:40:33,400 --> 00:40:39,000 Now, I want to display for 'tomcat7' configuration file and home, 727 00:40:39,000 --> 00:40:42,000 then I need to call this 'display_details()' method from your 728 00:40:42,000 --> 00:40:48,500 'tomcat7'. Let me call that. 'tomcat7.display_details()'. 729 00:40:48,500 --> 00:40:50,300 No need to pass any arguments. 730 00:40:50,300 --> 00:40:52,400 Anyway, by default 'self' is there, right. 731 00:40:52,400 --> 00:40:55,000 We need to pass 'self' value generally, 732 00:40:55,000 --> 00:40:56,900 but whenever if you run in this way, 733 00:40:56,900 --> 00:41:01,200 Python is going to convert your 'display_details()' in this way. 734 00:41:01,200 --> 00:41:03,700 [no audio] 735 00:41:03,700 --> 00:41:06,500 'tomcat7'. That's it. 736 00:41:06,500 --> 00:41:08,800 Because we are not having any arguments here. 737 00:41:08,800 --> 00:41:11,493 Now this 'tomcat7' is going to assign 'self', 738 00:41:11,400 --> 00:41:15,300 and inside of this, what we are having? 'self.tcf', means 739 00:41:15,300 --> 00:41:17,500 we are calling from 'tomcat7', right. 740 00:41:17,500 --> 00:41:22,000 That's why you are going to get 'tomcat7.tcf', 'tomcat7.th'. 741 00:41:22,000 --> 00:41:25,000 Right. See that. I'm going to run. 742 00:41:26,100 --> 00:41:28,200 See the results. You're getting 'tomcat7' details. 743 00:41:28,800 --> 00:41:31,000 Now, let me call for 'tomcat9'. 744 00:41:31,000 --> 00:41:33,000 [no audio] 745 00:41:33,000 --> 00:41:35,700 So, whenever if you are calling from particular object, based 746 00:41:35,700 --> 00:41:39,000 on that your Python is going to get variables for that object. 747 00:41:39,600 --> 00:41:43,200 See that. And I can call any number of times. 748 00:41:43,200 --> 00:41:46,300 First, I am going to call 'tomcat9.display_details()'. 749 00:41:47,800 --> 00:41:48,800 See that. 750 00:41:50,000 --> 00:41:54,400 So this is the advantage with your OOPS concept. Right. 751 00:41:56,700 --> 00:42:00,000 So, guys once again I am repeating, the important 752 00:42:00,000 --> 00:42:01,800 points for OOPS concept is. 753 00:42:03,000 --> 00:42:06,600 First, we are taking OOPS concept to create an object. 754 00:42:06,600 --> 00:42:08,600 So, in our program we created two objects. 755 00:42:08,600 --> 00:42:10,600 [no audio] 756 00:42:10,600 --> 00:42:12,810 So, what is the advantage by creating two objects? 757 00:42:12,800 --> 00:42:16,300 Dynamically we are going to create a separate memory location 758 00:42:16,300 --> 00:42:19,100 for your required object 759 00:42:19,100 --> 00:42:21,900 so that we can access any variable at any time. 760 00:42:21,962 --> 00:42:24,700 [no audio] 761 00:42:24,700 --> 00:42:29,200 Right. And basically OOPS is nothing but 762 00:42:30,000 --> 00:42:33,900 grouping related functions for particular thing 763 00:42:33,900 --> 00:42:36,000 under one name, that is called a template. 764 00:42:37,000 --> 00:42:38,000 Now, in reverse way 765 00:42:38,600 --> 00:42:40,800 we are creating template to create an object. 766 00:42:40,800 --> 00:42:45,000 Under template we are writing the related functions for that object. 767 00:42:45,000 --> 00:42:46,000 That's it. 768 00:42:46,000 --> 00:42:48,600 [no audio] 769 00:42:48,600 --> 00:42:50,200 Right. And one more thing, 770 00:42:51,300 --> 00:42:52,600 no need to write always 'self' here. 771 00:42:52,600 --> 00:42:53,710 You can write anything. 772 00:42:53,700 --> 00:42:55,600 Let's say I am writing instead of 'self', 773 00:42:55,600 --> 00:43:00,210 what I am doing is, so I will write suppose, "narendra". 774 00:43:00,200 --> 00:43:03,200 So, I am going to replace all with "narendra" only. 775 00:43:03,200 --> 00:43:04,700 Then it will work. No problem. 776 00:43:05,400 --> 00:43:09,400 The only thing is, universally we are following one rule. Instead 777 00:43:09,400 --> 00:43:12,700 of taking any random default argument, 778 00:43:12,700 --> 00:43:15,500 we are taking 'self'. But we can take anything. 779 00:43:16,200 --> 00:43:17,200 Let me write. 780 00:43:17,200 --> 00:43:19,200 [no audio] 781 00:43:19,200 --> 00:43:21,700 So, I'm going to replace all with "narendra". 782 00:43:21,700 --> 00:43:27,400 [no audio] 783 00:43:27,400 --> 00:43:30,210 Actually, that is my name, right. Now, see the result. 784 00:43:30,200 --> 00:43:31,200 There is no change. 785 00:43:31,200 --> 00:43:33,800 [no audio] 786 00:43:33,800 --> 00:43:36,000 So, but generally, universally we are following. 787 00:43:36,000 --> 00:43:37,900 [no audio] 788 00:43:37,900 --> 00:43:40,110 See, if I go with my name, 789 00:43:40,100 --> 00:43:42,500 if you go with your name, you will get somewhat confusion. 790 00:43:42,500 --> 00:43:45,400 That's why universally we are following default argument as 'self'. 791 00:43:45,400 --> 00:43:46,400 That's it. 792 00:43:46,400 --> 00:43:49,000 So, make sure that in the interview suppose if they ask, "What is 793 00:43:49,000 --> 00:43:52,110 the default argument for methods in class?" 794 00:43:52,100 --> 00:43:55,300 Then you have to say that, we can take anything, 795 00:43:55,300 --> 00:43:58,500 but universally we are following 'self' as the default argument. 796 00:43:58,500 --> 00:44:01,200 That's it. Okay. 797 00:44:01,900 --> 00:44:05,600 I hope you are getting at least some idea to use OOPS concept. 798 00:44:05,600 --> 00:44:09,600 Anyway, while going forward we will write some real-time scripts 799 00:44:09,600 --> 00:44:11,500 by taking some real-time scenarios 800 00:44:11,500 --> 00:44:13,600 so that you will be good with your OOPS concept. 801 00:44:13,600 --> 00:44:16,700 And one more very, very important point is, in case 802 00:44:16,700 --> 00:44:18,700 if you are not good with OOPS, 803 00:44:18,700 --> 00:44:21,900 don't worry at automation side. But if you are going to plan 804 00:44:21,900 --> 00:44:25,300 for application development or any GUI applications, 805 00:44:25,300 --> 00:44:28,000 something like that, you should be good with OOPS. That's it.