Differences
This shows you the differences between two versions of the page.
python_wiki:if_name_main [2014/11/19 22:07] billdozor created |
python_wiki:if_name_main [2019/05/25 23:50] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== if __name__ main ====== | ||
- | Many python source files include a section like this: | ||
- | |||
- | < | ||
- | if __name__ == ' | ||
- | main() | ||
- | </ | ||
- | |||
- | It may include other statements as well. | ||
- | |||
- | This special if statement is checked by the python interpreter itself when it reads the source file. | ||
- | |||
- | * If the source is being run as the main program, it sets that source file as the special " | ||
- | * If the source file is being imported from another module, the " | ||
- | |||
- | The entire reason behind this is: | ||
- | * Sometimes modules are written to be executed directly. | ||
- | * They could also be imported for use in another module. | ||
- | * The main check allows for only the " |