3 ms·
And still I do write a main procedure in Python usually, which is called from that if __name__ == "__main__" thing. It is convenient to leave the top level asap
by zelphirkalt 6y ago
And still I do write a main procedure in Python usually, which is called from that if __name__ == "__main__" thing. It is convenient to leave the top level asap and begin as quickly as possible to use procedures/function, getting out of the area, where one can accidentally change global variables, without noticing (in procedures you would have to write global as a keyword and would hopefully then notice you are doing something possibly dangerous).
- quietbritishjim 6y agoAbsolutely. But on the other hand, it's still very useful that Python does work like this: it's nice to be able to directly do things at the top level (e.g. setting up "constants" with a little computation, conditionally importing modules or importing fallbacks, etc.). As the article says, it's also an extremely clean way of defining what gets run in what order during startup.
- tcbasche 6y agoPycharm also puts a handy play button on it too, which is literally the only reason I do it. (sheer laziness)