optparse: usage

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • spacecoyote
    New Member
    • Nov 2006
    • 15

    optparse: usage

    I tried this:

    Code:
    usage = "Something, by Spacecoyote\nusage: %prog file [options]"
    parser = OptionParser(usage)
    Code:
    test.py --help
    and I expected:
    Code:
    Something, by Spacecoyote
    usage: test.py file [options]
    but I got:
    Code:
    usage: Something, by Spacecoyote
    usage: test.py file [options]
    Is there an easy way to make optparse not force the usage prompt to start with usage? Or do I have to implement this myself.
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    I don't know of a way to do it other than changing the source file.
    Code:
    def format_usage (self, usage):
            return "%s" % usage
    
    parser = OptionParser(usage='Something, by Spacecoyote\n%prog file [options]',
                          prog='YourFile.py', version='x.x',
                          description='This does not do anything'
                          )
    opt, args = parser.parse_args()
    Output:
    Code:
    >>> Something, by Spacecoyote
    YourFile.py file [options]
    This does not do anything
    options:
      --version   show program's version number and exit
      -h, --help  show this help message and exit

    Comment

    Working...