Parsing command line options in Python

1
2
import sys, getopt, os.path
me = os.path.basename(sys.argv[0])
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Code snippet for parsing command line options (using the getopt module) in a sophisticated way.

In this example, the program accepts three options (both as one-letter options and as long options) and requires at least two arguments.


#python #code #cesarnog #commandLine

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.