myusuf3 myusuf3 -4 years ago 79
Python Question

What does this mean exit (main())

I have seen this in a couple of python script I have been reading lately. I have looked at the doc; they only give examples deal with passing a termination value or string of some sort.

I think what this does is call the main method, then exit?

If someone could shed some light on this I would appreciate it.

if __name__ == "__main__":
exit (main())

Please and thank you

Answer Source

This will call the function main() and when main finishes, it will exit giving the system the return code that is the result of main().

A simplified example where this might be used:

def main():
        return 0
        return 1

if __name__ == "__main__":
    exit (main())
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download