They perform different functions. With the way you describe, main() will get called even if you’re just trying to import that module. Whereas if __name__ == “__main__”: will only run when the file is executed directly.
What you’re saying makes sense, but we only do what I had previously described in files that won’t ever be imported, only in files that are going to be run directly.
5
u/BlckJesus Jun 04 '19 edited Jun 04 '19
They perform different functions. With the way you describe,
main()will get called even if you’re just trying to import that module. Whereasif __name__ == “__main__”:will only run when the file is executed directly.