Prev | Index | NextCatching Exceptions
- An example pulled from the documentation for the getopt module
- Illustrates an idiomatic way for parsing command line arguments
import getopt, sys
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "ho:", ["help", "output="])
except getopt.GetoptError:
# print help information and exit:
usage()
sys.exit(2)
...etc...
getopt.getopt will 'raise' a getopt.GetoptError if incorrect command line arguments were specified
An Introduction To Python