ITeye博客

Example of Using getopt in Python

standalone · 2009-07-24 12:31 · python · Markdown

import getopt, sys

def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], "ho:v", ["help", "output="])
    except getopt.GetoptError:
        # print help information and exit:
        usage()
        sys.exit(2)
    output = None
    verbose = False
    for o, a in opts:
        if o == "-v":
            verbose = True
        if o in ("-h", "--help"):
            usage()
            sys.exit()
        if o in ("-o", "--output"):
            output = a

 中午详细解释看这里。

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。