flâneur — a map of the web's best reading

__main__ — Top-level code environment — Python 3.12.4 documentation

docs.python.org · 1,928 words · saved by 1 readers

the name of the top-level environment of the program, which can be checked using the __name__ == '__main__' expression; and the __main__.py file in Python packages. Both of these mechanisms are related to Python modules; how users interact with them and how they interact with each other. They are explained in detail below. If you’re new to Python modules, see the tutorial section Modules for an introduction. When a Python module or package is imported, __name__ is set to the module’s name. Usually, this is the name of the Python file itself without the .py extension: If the file is part of a package, __name__ will also include the parent package’s path: However, if the module is executed in the top-level code environment, its __name__ is set to the string '__main__'. __main__ is the name of the environment where top-level code is run. “Top-level code” is the first user-specified Python module that starts running. It’s “top-level” because it imports all other modules that the program ne

__main__ — Top-level code environment — Python 3.14.6 documentation Navigation index modules | next | previous | Python » 3.14.6 Documentation » The Python Standard Library » Python Runtime Services » __main__ — Top-level code environment | Theme Auto Light Dark | __main__ — Top-level code environment ¶ In Python, the special name __main__ is used for two important constructs: the name of the top-level environment of the program, which can be checked using the __name__ == '__main__' expression; and the __main__.py file in Python packages. Both of these mechanisms are

Explore this link on the map →

related reading