An Explanation of:

if __name__=='__main__':
    sys.exit(main())


Explanation

If you execute a Python script directly, __name__ is set to "__main__", but if you import it from another script, it is not.

So in this case, the script is seeing if you're executing it directly. If it is, it calls the main() function to perform some work, and returns the return value of the main() function to the system via exit(). If the script is being imported from another module, it doesn't execute the main() function and simply provides the script's functions and classes to the importing script.

This is a common idiom in Python. It allows you to have scripts that are standalone programs, but can also be imported without trying to do work that the importing script doesn't want done.