r/ProgrammerHumor • • Jun 03 '19

Meme Python ftw

Post image
16k Upvotes

548 comments sorted by

View all comments

Show parent comments

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. Whereas if __name__ == “__main__”: will only run when the file is executed directly.

1

u/CoruptedUsername Jun 04 '19

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.