Python optparse metavar

I am not sure what optparse's metavar parameter is used for. I see it is used all around, but I can't see its use.

Can someone make it clear to me? Thanks.


As @Guillaume says, it's used for generating help. If you want to have an option that takes an argument, such as a filename, you can add the metavar parameter to the add_option call so your preferred argument name/descriptor is output in the help message. From the current module documentation:

usage = "usage: %prog [options] arg1 arg2"
parser = OptionParser(usage=usage)
parser.add_option("-f", "--filename",
                  metavar="FILE", help="write output to FILE"),

would produce help like this:

usage: <yourscript> [options] arg1 arg2

  -f FILE, --filename=FILE

The "FILE" after the "-f" and the "--filename" comes from the metavar.

Need Your Help

HttpContext IP Problem

c# httpcontext ipv6 ipv4

I have a problem when I use HttpContext.Current.Request.UserHostAddress, some times returns "" (IPv4) and some times returns "fe80::99be:a05d:7938:1c30%8" (IPv6), calling from the same

git workflow with main svn repository using git-svn

git git-svn

I'm in a big team which uses SVN as the revision control.