The main use I’ve found for the Python sys module is allowing command-line arguments to be made to a script. Here is an example of how it looks:
import sys if len(sys.argv) == 2: input_file = sys.argv else: print "Please input a command-line argument specifying the file"
This script checks that 2 command-line arguments had been passed to the program before assigning the value sys.argv to a variable. We check for two command-line arguments because the first one (sys.argv) is the name of the Python script currently being executed.