1 00:00:00,210 --> 00:00:02,300 Hello welcome to this tutorial. 2 00:00:03,300 --> 00:00:11,430 And in this tutorial we will talk about the attribute double underscore name I mean the command prompt 3 00:00:11,620 --> 00:00:21,140 now and I have started the Python interpreter before performing any operations in the Python interpreter. 4 00:00:21,210 --> 00:00:34,740 I'm going to call the D I add function so let's call this function d I and he had the desired function 5 00:00:34,770 --> 00:00:45,420 has returned the list of objects in the current scope the double underscore Bolton's is a module the 6 00:00:45,480 --> 00:00:54,120 double underscore dog attribute is a string that can be used for documentation of a method or a function 7 00:00:54,270 --> 00:00:55,630 clause etc.. 8 00:00:56,730 --> 00:01:04,380 And then we have the double underscore name which we are going to talk about in detail. 9 00:01:04,380 --> 00:01:11,520 Now let's see what are the different attributes available in the Bolton's module. 10 00:01:11,790 --> 00:01:21,410 So let's pass this to the desired function so these are the different attributes that are available 11 00:01:21,410 --> 00:01:22,580 to us. 12 00:01:22,580 --> 00:01:30,170 And here we can see a lot of functions that we have been using the print function the idea function 13 00:01:30,230 --> 00:01:35,890 input and on a host of other functions that we have been using. 14 00:01:36,200 --> 00:01:45,790 And without even importing any module we have access to all of the modules in this building module. 15 00:01:45,800 --> 00:01:55,220 Now coming to the double underscore the name attribute let's print this out and this attribute has been 16 00:01:55,280 --> 00:02:01,600 assigned a value double underscored mean when we start python. 17 00:02:01,610 --> 00:02:09,740 There are a few environmental objects that are set up and by default the attribute double underscored 18 00:02:09,750 --> 00:02:20,390 name is assigned a value main as you can see here Python interpreter has assigned a value Maine to this 19 00:02:20,510 --> 00:02:27,610 attribute w underscored name and here I have created a file. 20 00:02:28,780 --> 00:02:31,210 And in this file we have defined a function. 21 00:02:31,330 --> 00:02:32,300 Hello. 22 00:02:32,320 --> 00:02:36,380 And this brings the text hello world. 23 00:02:36,660 --> 00:02:37,620 No. 24 00:02:37,660 --> 00:02:45,630 And then we are also going to print the attributes available in the namespace of the module. 25 00:02:45,730 --> 00:02:51,560 And we're going to check the value of the attribute double underscored. 26 00:02:51,580 --> 00:02:59,860 Name and every module that we create has a built in attribute double underscore name. 27 00:03:00,530 --> 00:03:08,630 And we are going to run this script and see what value has been assigned to this attribute. 28 00:03:08,700 --> 00:03:10,070 Double underscored need. 29 00:03:10,760 --> 00:03:17,250 So let's execute this script from the command prompt in your window system. 30 00:03:17,250 --> 00:03:25,890 You can pass the positive part of your test script as an argument to the Python interpreter not to execute 31 00:03:25,890 --> 00:03:30,490 the file directly going to say Python space. 32 00:03:30,510 --> 00:03:42,150 And then the part of your program or your module and then hit enter so using the desired function we 33 00:03:42,150 --> 00:03:48,240 have rendered the attributes that are available in the namespace of the module. 34 00:03:48,270 --> 00:03:53,820 And here we have the double underscore name as an attribute. 35 00:03:53,820 --> 00:04:02,390 Now using the print function again we want to see the value that has been assigned to this attribute. 36 00:04:02,400 --> 00:04:03,900 Double underscored. 37 00:04:03,990 --> 00:04:07,320 Name and this time as well. 38 00:04:07,500 --> 00:04:14,700 The python interpreter as a sign the value main double underscored main to this attribute. 39 00:04:14,700 --> 00:04:17,340 And then we have a call to the function. 40 00:04:17,520 --> 00:04:18,040 Hello. 41 00:04:18,720 --> 00:04:23,440 So we have directly executed the script or the module. 42 00:04:23,580 --> 00:04:33,300 And as we can see when we directly execute a script the double underscore name attribute has been assigned 43 00:04:33,300 --> 00:04:37,270 this value double underscore Main. 44 00:04:37,360 --> 00:04:47,190 Now I'm going to import this same module and see what the value of this attribute is going to be this 45 00:04:47,190 --> 00:04:49,530 time when we import the module. 46 00:04:49,890 --> 00:04:52,440 So let's do that. 47 00:04:52,530 --> 00:04:55,290 No let import the script. 48 00:04:55,290 --> 00:05:04,880 Import test is the module name and then enter here. 49 00:05:05,070 --> 00:05:13,410 The first line here displays the list of attributes available in the namespace of the module. 50 00:05:13,770 --> 00:05:15,590 So we have the double underscored. 51 00:05:15,590 --> 00:05:25,970 Name and then we have a print function which displays the value of this attribute w underscored name. 52 00:05:25,970 --> 00:05:32,450 This time it has been assigned the name of the module test. 53 00:05:32,450 --> 00:05:35,010 This is the module that we have imported. 54 00:05:35,180 --> 00:05:43,740 When we have executed a module directly bypassing the module to the Python interpreter. 55 00:05:43,760 --> 00:05:52,280 The attribute double underscore name has been assigned this value double underscore mean then we have 56 00:05:52,400 --> 00:06:02,930 imported the module the attribute double underscore name has been assigned the value that is the module 57 00:06:03,080 --> 00:06:15,210 name a module can discover whether or not it is joining in the main score by checking its own double 58 00:06:15,270 --> 00:06:16,080 underscored. 59 00:06:16,080 --> 00:06:17,610 Name attribute. 60 00:06:17,730 --> 00:06:29,430 So a module can discover if it is being executed directly like this or if any external program is importing 61 00:06:29,550 --> 00:06:35,710 this module into its current scope using this attribute double underscored. 62 00:06:35,710 --> 00:06:41,160 Name if it is being executed directly as a standalone program. 63 00:06:41,220 --> 00:06:47,400 This is the value that the module that the attribute WMD code name get assigned. 64 00:06:47,550 --> 00:06:54,900 If it is being imported the module name gets assigned to the attribute w underscored. 65 00:06:54,900 --> 00:07:02,970 Name or when a python interpreter execute a script before executing the script it defines a few special 66 00:07:02,970 --> 00:07:05,940 variables for example. 67 00:07:06,030 --> 00:07:14,700 The double underscored name variable and by default it is set to double underscored made in a module 68 00:07:14,700 --> 00:07:23,490 can discover whether it is being executed just as a standalone program or if it is being imported using 69 00:07:23,580 --> 00:07:27,710 this variable or the attribute double underscored. 70 00:07:27,720 --> 00:07:37,020 Name and if the module is being imported to an external program and the attribute double underscored 71 00:07:37,050 --> 00:07:48,180 name get the value of devalue module name or the file name. 72 00:07:48,240 --> 00:07:55,820 This condition can be used in a module in order to execute a piece of code. 73 00:07:56,070 --> 00:08:05,490 A block of code so when the module is executed directly this condition becomes true. 74 00:08:05,850 --> 00:08:14,520 And this block of code gets executed if a module is imported by an external program then this condition 75 00:08:14,520 --> 00:08:19,580 becomes false and they skip executing this block of code.