3 ms·
I never understood why people bother with this when writing their python main file, which is never going to be imported because it doesn't make sense in the fir
by jraph 2y ago
I never understood why people bother with this when writing their python main file, which is never going to be imported because it doesn't make sense in the first place.
- elteto 2y agoBecause I dislike interspersing executable statements at module level with function definitions. I’d rather have all code live inside functions and have one main entry point for the script. It’s just a personal preference, nothing wrong with not doing that though.
- jraph 2y agoBut you could have a single main() call without the if statement, couldn't you?
- telotortium 2y agoREPL-based development. You might be developing a script, but notice a bug. If you import your script as a module, you can run the function you’re debugging, figure out what’s wrong, edit the file, and then reimport the module (using importlib.reload).
- jraph 2y agoOkay, that's quite convincing, thanks!