How about some syntactic sugar for " __name__ == '__main__' "?
rosuav at gmail.com
Thu Nov 13 00:26:50 CET 2014
On Thu, Nov 13, 2014 at 10:19 AM, Terry Reedy <tjreedy at udel.edu> wrote:
> Functions have an implicit 'return None' at the end (which, in CPython,
> become an explicit pair of bytecodes, even when the function already ends
> with return something'. The simplest proposal is that modules have an
> implicit "if __name__ == '__main__': main()" at the end. I think this would
> not have to be added to the bytecode.
> This magical invocation mimics C and some other languages, and I think it
> works well.
Yes, but it conflicts with the existing and common usage of having
that explicitly in the code. Safer - and more in line with the way
other such functions are written - would be a dunder function:
if __name__ == '__main__': __main__()
More information about the Python-list