Great question — answering as the UphillTech team:
Short Answer It's boilerplate code that protects users from accidentally invoking the script when they didn't intend to. Here are some common problems when the guard is omitted from a script: If you import the guardless script in another script (e.g. import my_script_without_a_name_eq_main_guard ), then the latter script will trigger the former to run at import time and using the second script's command line arguments . This is almost always a mistake. If you have a custom class in the guardless script and save it to a pickle file, then unpickling it in another script will trigger an import of the guardless script, with the same problems outlined in the previous bullet. Long Answer To...
Full answer by Mr Fooz: https://stackoverflow.stackexchange.com/a/419185 (CC BY-SA 4.0).
Need it done for your business? UphillTech.