Python - OptionParser

时间:2015-09-06 19:45:51

标签: python

我是python的新手。 谁能告诉我如何删除下面的“无”输出?

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

1 个答案:

答案 0 :(得分:2)

删除#!/bin/sh sudo umount /Users sudo mkdir -p /Users/myuser sudo /usr/local/etc/init.d/nfs-client start sudo mount 192.168.99.1:/Users/myuser /Users/myuser -o rw,async,noatime,rsize=32768,wsize=32768,proto=tcp,nfsvers=3 行。这是docstrings