命令行参数

import optparse
def parse_args():
    usage = """
    How to use parser options

    """
    parser = optparse.OptionParser(usage)
    help = "The port to listen on."
    parser.add_option('--port', type='int', help=help)
    parser.add_option('--iface', default='localhost')
    options, args = parser.parse_args()
    print args
    print options

parse_args()

如文件为tp.py

要显示帮助: tp.py --help

display:

Usage:
How to use parser options


Options:
-h, --help show this help message and exit
--port=PORT The port to listen on.

你可能感兴趣的:(命令行)