this post was submitted on 28 May 2025
239 points (96.9% liked)
Programmer Humor
35949 readers
83 users here now
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
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.py
without this breaking. Right now this only breaks for files called__main__.py
but luck would have it that calling a file__main__.py
already 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.