optparse模块是python自带的模块,可用于处理命令行
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" __author__:JasonLIN """
from optparse import OptionParser
parse = OptionParser()
parse.add_option("-f", dest="filename",
help="write report to file")
(options, args) = parse.parse_args()
print(options, args)
# {"fileanme: None"} ["ff", "df"]
## {'filename': 'test'} []
print(options.filename)
# None
## test
"""
python optparse模块.py ff df #
python optparse模块.py -f test ##
"""