[Python-ideas] Just __main__
mikegraham at gmail.com
Mon Jun 18 19:25:11 CEST 2012
On Mon, Jun 18, 2012 at 1:12 PM, Serhiy Storchaka <storchaka at gmail.com> wrote:
> No, it is much easier.
> import sys
> if __main__ if sys.version_info >= (3, 9) else __name__ == '__main__':
> except NameError:
> __main__ = __name__ == '__main__'
> if __main__:
That's nonsense. If you wanted to support old Python versions, you'd
write `if __name__ == '__main__'` (there's no reason __name__ would
change its behavior). If the oldest version you wanted to support had
this feature, you're write `if __main__`. This is the way every other
new feature works. (It even has the advantage of failing loudly if you
try to do it on an older version of Python.)
That being said, I'm -0 on the feature. I don't think it's really much
easier to explain or worth any effort.
More information about the Python-ideas