Understanding __name__ == “__main__” in Python


Use this snippet to make a Python file executable as a script or importable as a module.

Source Code

if __name__ == "__main__":
    # code to execute if called from command-line
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments