command line arguments common utility scripts often need to process command line arguments these arguments are stored in the sys module' argv attribute as list for instance the following output results from running python demo py one two three at the command lineimport sys print(sys argv['demo py''one''two''three'the getopt module processes sys argv using the conventions of the unix getopt(function more powerful and flexible command line processing is provided by the argparse module error output redirection and program termination the sys module also has attributes for stdinstdoutand stderr the latter is useful for emitting warnings and error messages to make them visible even when stdout has been redirectedsys stderr write('warninglog file not found starting new one\ 'warninglog file not found starting new one the most direct way to terminate script is to use sys exit( string pattern matching the re module provides regular expression tools for advanced string processing for complex matching and manipulationregular expressions offer succinctoptimized solutionsimport re re findall( '\bf[ - ]*''which foot or hand fell fastest'['foot''fell''fastest're sub( '(\ [ - ]+\ ' '\ ''cat in the the hat''cat in the hatwhen only simple capabilities are neededstring methods are preferred because they are easier to read and debug'tea for tooreplace('too''two''tea for two mathematics the math module gives access to the underlying library functions for floating point mathimport math math cos(math pi math log( the random module provides tools for making random selections brief tour of the standard library