if __name__ = '__main__'

## Understanding of if __name__ = "__main__"

Usually, object-oriented languages, such as java, c++, etc., have a program entry, the main() function, while python, a scripting language, has no entry function.

Usually, at the beginning of python code, when using from some import A, the main() function in some will be called when importing, so this method is introduced.


``` if __name__ = '__main__' ``` is equivalent to a simulated program entry.


python has a python -m xxxx.py command that runs the module as a script,
which is just an idiom.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324980933&siteId=291194637