why a main() function?

billie gnewsg at gmail.com
Tue Sep 19 03:57:07 EDT 2006


Another advantage is that you can catch all the unhandled exceptions of
the entire program (it they occurs) by doing something like this:

def another_call():
    raise SomeUnexpectedException   # it will be catched in '__main__'

def call():
    another_call()

def run():
    call()

in __name__ == '__main__':
    try:
         run()
    except:
         # do cleanup
         # log exit message
         # exit




More information about the Python-list mailing list