Hello welcome to this tutorial.
And in this tutorial we will talk about the attribute double underscore name I mean the command prompt
now and I have started the Python interpreter before performing any operations in the Python interpreter.
I'm going to call the D I add function so let's call this function d I and he had the desired function
has returned the list of objects in the current scope the double underscore Bolton's is a module the
double underscore dog attribute is a string that can be used for documentation of a method or a function
clause etc..
And then we have the double underscore name which we are going to talk about in detail.
Now let's see what are the different attributes available in the Bolton's module.
So let's pass this to the desired function so these are the different attributes that are available
to us.
And here we can see a lot of functions that we have been using the print function the idea function
input and on a host of other functions that we have been using.
And without even importing any module we have access to all of the modules in this building module.
Now coming to the double underscore the name attribute let's print this out and this attribute has been
assigned a value double underscored mean when we start python.
There are a few environmental objects that are set up and by default the attribute double underscored
name is assigned a value main as you can see here Python interpreter has assigned a value Maine to this
attribute w underscored name and here I have created a file.
And in this file we have defined a function.
Hello.
And this brings the text hello world.
No.
And then we are also going to print the attributes available in the namespace of the module.
And we're going to check the value of the attribute double underscored.
Name and every module that we create has a built in attribute double underscore name.
And we are going to run this script and see what value has been assigned to this attribute.
Double underscored need.
So let's execute this script from the command prompt in your window system.
You can pass the positive part of your test script as an argument to the Python interpreter not to execute
the file directly going to say Python space.
And then the part of your program or your module and then hit enter so using the desired function we
have rendered the attributes that are available in the namespace of the module.
And here we have the double underscore name as an attribute.
Now using the print function again we want to see the value that has been assigned to this attribute.
Double underscored.
Name and this time as well.
The python interpreter as a sign the value main double underscored main to this attribute.
And then we have a call to the function.
Hello.
So we have directly executed the script or the module.
And as we can see when we directly execute a script the double underscore name attribute has been assigned
this value double underscore Main.
Now I'm going to import this same module and see what the value of this attribute is going to be this
time when we import the module.
So let's do that.
No let import the script.
Import test is the module name and then enter here.
The first line here displays the list of attributes available in the namespace of the module.
So we have the double underscored.
Name and then we have a print function which displays the value of this attribute w underscored name.
This time it has been assigned the name of the module test.
This is the module that we have imported.
When we have executed a module directly bypassing the module to the Python interpreter.
The attribute double underscore name has been assigned this value double underscore mean then we have
imported the module the attribute double underscore name has been assigned the value that is the module
name a module can discover whether or not it is joining in the main score by checking its own double
underscored.
Name attribute.
So a module can discover if it is being executed directly like this or if any external program is importing
this module into its current scope using this attribute double underscored.
Name if it is being executed directly as a standalone program.
This is the value that the module that the attribute WMD code name get assigned.
If it is being imported the module name gets assigned to the attribute w underscored.
Name or when a python interpreter execute a script before executing the script it defines a few special
variables for example.
The double underscored name variable and by default it is set to double underscored made in a module
can discover whether it is being executed just as a standalone program or if it is being imported using
this variable or the attribute double underscored.
Name and if the module is being imported to an external program and the attribute double underscored
name get the value of devalue module name or the file name.
This condition can be used in a module in order to execute a piece of code.
A block of code so when the module is executed directly this condition becomes true.
And this block of code gets executed if a module is imported by an external program then this condition
becomes false and they skip executing this block of code.