The values in \ _ \ _ name \ _ \ _ are as follows.
Configuration to run . ├── entry_point.py └── test_module.py
entry_point.py
# coding: utf-8
if __name__ == "__main__":
    #When called as an entry point
    # __name__To"__main__"Contains a character string
    # ex) python entry_point.py
    print "__main__!!"
else:
    #When called as a module such as import from others
    # __name__Is the module name
    # ex) python test_module.py
    # __name__ == "entry_point"
    print __name__
test_module.py
import entry_point
When entry_point.py is executed % python entry_point.py __main__!!
When test_module.py is executed % python test_module.py entry_point
It seems that the value to be entered changes depending on the execution method.
Recommended Posts