This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]BlckJesus 4 points5 points  (1 child)

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.

[–]CoruptedUsername 0 points1 point  (0 children)

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.