-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Python for Geeks
By :
Whenever the Python interpreter interacts with an import or equivalent statement, it does three operations, which are described in the next sections.
The Python interpreter searches for the specified module on a sys.path (to be discussed in the Accessing packages from any location section) and loads the source code. This has been explained in the Learning how import works section.
In this step, the Python interpreter defines a few special variables, such as __name__, which basically defines the namespace that a Python module is running in. The __name__ variable is one of the most important variables.
In the case of our example of the calcmain1.py, mycalculator.py, and myrandom.py modules, the __name__ variable will be set for each module as follows:
Table 2.1 – The __name__ attribute value for different modules
There are two cases of setting the __name__...