I'm aware of the standard example: if you execute a module directly then it's __name__
global variable is defined as "__main__"
. However, nowhere in the documentation can I find a precise description of how __name__
is defined in the general case. The module documentation says...
Within a module, the module's name (as a string) is available as the value of the global variable
__name__
.
...but what does it mean by "the module's name"? Is it just the name of the module (the filename with .py
removed), or does it include the fully-qualified package name as well?
How is the value of the __name__
variable in a Python module determined? For bonus points, indicate precisely where in the Python source code this operation is performed.