2015-09-06 46 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