[PYTHON] Contents of __name__

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

Contents of __name__
[Note] Contents of shape [0], shape [1], shape [2]
__name__
taichi's Torisetsu ⓪ Table of contents
Simulation of the contents of the wallet
[Linux] [Initial Settings] Table of Contents
yolov5 visualization program table of contents
Easy encryption of file contents (Python)
Contents of HTML escaping process of Jinja2
[Python] [Table of Contents Links] Python Programming
Understand the contents of sklearn's pipeline
[Translation] scikit-learn 0.18 Tutorial Table of Contents
See the contents of Kumantic Segumantion
Python Math Series ⓪ Table of Contents
Github Interesting Repository ⓪ Table of Contents
Introductory table of contents for python3
A memorandum of closure survey contents
I checked the contents of docker volume
2014/02/28 Summary of contents demoed at #ssmjp, part 1
[Translation] scikit-learn 0.18 User Guide Table of Contents
[Basics of python basics] Why do __name__ == "__main__"
Read all the contents of proc / [pid]
Set the process name of the Python program
Get the contents of git diff from python
Nogizaka recognition program (using Yolov5) Table of contents
The contents of the Python tutorial (Chapter 2) are itemized.
The contents of the Python tutorial (Chapter 8) are itemized.
The contents of the Python tutorial (Chapter 1) are itemized.
Origin of that name related to programming # 1 Language name 1
Let Code Table of Contents Starting from Zero
The contents of the Python tutorial (Chapter 10) are itemized.
Rewrite the name of the namespaced tag with lxml
Automating simple tasks with Python Table of contents
About the development contents of machine learning (Example)
The contents of the Python tutorial (Chapter 6) are itemized.
The contents of the Python tutorial (Chapter 3) are itemized.
Create a table of contents with IPython notebook