3 ms·
You only need the __main__ magic if you want a python file to be both a module and an executable script. This is a moderately advanced requirement. Beginners wi
by andybak 6y ago
You only need the __main__ magic if you want a python file to be both a module and an executable script. This is a moderately advanced requirement. Beginners will tend to write scripts OR importable modules.
- deleted 6y ago[deleted]
- geoelectric 6y agoFor debugging-in-REPL purposes it's often very convenient to have it both ways. I was taught as a beginner to treat it as idiomatic boilerplate for that reason--no harm in having it, and there when you need it. Then you can just import your script and ad hoc test your functions. It's a good technique prior to introducing formal unit testing (and even then, supplemental ad hoc has advantages).