logoalt Hacker News

zmgsabsttoday at 1:30 AM1 replyview on HN

> __name__ == "__main__"

What makes this weirder than other languages detecting if they’re an import or an invoked file?


Replies

scoofytoday at 6:36 AM

It’s only weird syntactically. Python tends to lean towards intuitive, natural language by default. I would have assumed they’d have created a syntactically straightforward alternative, like:

__this_file__ == “__launch_file__”

or similar. I understand python values “only one way” of doing things, but it would be helpful for readability.