- cross-posted to:
- programmer_humor@programming.dev
- cross-posted to:
- programmer_humor@programming.dev
Also, do y’all call main() in the if block or do you just put the code you want to run in the if block?
Also, do y’all call main() in the if block or do you just put the code you want to run in the if block?
I mean yeah with no context that looks weird A/F, but given a couple details it’s fairly self-evident why it be like it do.
__name__is a global variable containing the name of the current module. There’s a couple more like__file__containing the filename of the current module.__name__gets set to"__main__". If it got set to something more sensible like"main"you couldn’t really call a filemain.pywithout this breaking. Right now this only breaks for files called__main__.pybut luck would have it that calling a file__main__.pyalready has a special meaning which makes these uses not clash.__name__is set to__main__is the easiest way to do this.Python for sure has a bunch of weirdness, but it all does mesh together into a rather nice programming language.