Is there any advantage to using a main() in python scripts?

JL lightaiyee at gmail.com
Wed Dec 11 04:55:44 EST 2013


Python scripts can run without a main(). What is the advantage to using a main()? Is it necessary to use a main() when the script uses command line arguments? (See script below)

#!/usr/bin/python

import sys

def main():
    # print command line arguments
    for arg in sys.argv[1:]:
        print arg

if __name__ == "__main__":
    main()



More information about the Python-list mailing list