input and output his describes the basics of python input and output ( / )including command-line optionsenvironment variablesfile /ounicodeand how to serialize objects using the pickle module reading command-line options when python startscommand-line options are placed in the list sys argv the first element is the name of the program subsequent items are the options presented on the command line after the program name the following program shows minimal prototype of manually processing simple command-line argumentsimport sys if len(sys argv! sys stderr write("usage python % inputfile outputfile\nsys argv[ ]raise systemexit( inputfile sys argv[ outputfile sys argv[ in this programsys argv[ contains the name of the script being executed writing an error message to sys stderr and raising systemexit with non-zero exit code as shown is standard practice for reporting usage errors in command-line tools although you can manually process command options for simple scriptsuse the optparse module for more complicated command-line handling here is simple exampleimport optparse optparse optionparser(an option taking an argument add_option("- ",action="store",dest="outfile" add_option("--output",action="store",dest="outfile"an option that sets boolean flag add_option("- ",action="store_true",dest="debug" add_option("--debug",action="store_true",dest="debug"set default values for selected options set_defaults(debug=falseparse the command line optsargs parse_args(retrieve the option settings outfile opts outfile debugmode opts debug lib fl ff