[Python-ideas] Just __main__

Ethan Furman ethan at stoneleaf.us
Mon Jun 18 22:24:28 CEST 2012

Massimo DiPierro wrote:
> how about a decorator that have the same effect as calling the function 
> is __name__=='__main__'?

I believe several have been written... something like (untested):

def main(automagically_run):
   if __name__ == 'main':
   return automagically_run  # assuming SystemExit wasn't raised ;)


More information about the Python-ideas mailing list