optparse模块用于从命令行直接读取参数,用法基本与 argparse模块 一致,如下:

#!/usr/bin/env python
#-*- coding:utf-8 -*-

from optparse import OptionParser

parser = OptionParser("Usage: xxxx")
parser.add_option('-c', '--chars', dest='characters', action='store_true', default=False, help='only count characters')
parser.add_option('-w', '--words', dest='words', action='store_true', default=False, help='only count words')
parser.add_option('-l', '--lines', dest='lines', action='store_true', default=False, help='only count lines')
options.args = parser.parse_args()
if options.characters: xxxxx elif options.words: xxxxx elif options.lines: xxxxx else: xxxxx

 

 

 

 

 

 

 

    

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-06
  • 2021-06-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-06
猜你喜欢
  • 2021-10-24
  • 2022-01-31
  • 2022-01-15
  • 2022-12-23
  • 2021-12-23
  • 2022-02-20
  • 2022-12-23
相关资源
相似解决方案