[Python-ideas] Replacing the if __name__ == "__main__" idiom (was Re: making a module callable)

Chris Angelico rosuav at gmail.com
Mon Nov 25 05:21:47 CET 2013


On Mon, Nov 25, 2013 at 3:14 PM, Ron Adam <ron3200 at gmail.com> wrote:
> And how about just a global name __main__ that is always set to "__main__"?
>
>    if __name__ is __main__:
>          ...
>
> Not a big change, but it reads nice and maybe users will like it well enough
> not to keep suggesting changing it. ;-)

But then you have to explain why you're using 'is' to compare strings,
which shouldn't normally be done. Why not just use == as per current?

ChrisA


More information about the Python-ideas mailing list