re: What's the use of if __name__ == '__main__': in Python? VIEW POST


The way I think about it, is as a main method like in c++. Unless you have another 'main' on another module and import it somewhere else in that case main will not execute. So is safe to assume that you should only have one main entry point in your whole program.

I think the best way to explain it to a beginner would be to write some script without using main, and another script with using main running it and seeing the execution results in the console. At least that's how I learn stuff lol.

Here's an overcomplicated answer on SO.

code of conduct - report abuse