2015-09-06 34 views
-1

我是一个Python新手。 任何人都可以告诉我如何删除下面的“无”输出?Python - OptionParser

def main(argv=None): 

    if argv is None: argv = sys.argv 

    usage = "%prog [options] [command]" 
    parser = OptionParser(usage=usage, add_help_option=False, 
          version="version %s" % VERSION) 

    parser.add_option("-v", action="count", dest="verbose", 
         help="print extra messages to stdout") 

    # help displays the module doc text plus the option help 
    def doHelp(option, opt, value, parser): 
     print(__doc__) 
     parser.print_help() 
     sys.exit(0) 

    parser.add_option("-h", "--help", 
         help="show help message and exit", 
         action="callback", callback=doHelp) 

输出:

[root ~]# ./test.py -h 
None 
Usage: test.py [options] [command] 

Options: 
    --version    show program's version number and exit 
+0

'__doc__'是'None' –

回答

2

卸下print(__doc__)线。这是docstrings

+0

谢谢,jtbandes 它就像你说的那样工作 – Jon

相关问题