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.

Answers


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

options:
  -f FILE, --filename=FILE

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


Need Your Help

Remove \n and everything afterward in mysql column

mysql

I have a mysql table like the example below. Sometimes there is an extra line a \n the column with info afterward that I do not need and I would like to remove it keeping only the first line. How w...

Changing from arrays TO struct containing arrays

c++ arrays deque

I am changing my code so it would fit me better .

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.