473,394 Members | 2,063 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

optparse: usage

I tried this:

Expand|Select|Wrap|Line Numbers
  1. usage = "Something, by Spacecoyote\nusage: %prog file [options]"
  2. parser = OptionParser(usage)
Expand|Select|Wrap|Line Numbers
  1. test.py --help
and I expected:
Expand|Select|Wrap|Line Numbers
  1. Something, by Spacecoyote
  2. usage: test.py file [options]
but I got:
Expand|Select|Wrap|Line Numbers
  1. usage: Something, by Spacecoyote
  2. 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.
Jan 19 '07 #1
1 1972
bvdet
2,851 Expert Mod 2GB
I don't know of a way to do it other than changing the source file.
Expand|Select|Wrap|Line Numbers
  1. def format_usage (self, usage):
  2.         return "%s" % usage
  3.  
  4. parser = OptionParser(usage='Something, by Spacecoyote\n%prog file [options]',
  5.                       prog='YourFile.py', version='x.x',
  6.                       description='This does not do anything'
  7.                       )
  8. opt, args = parser.parse_args()
  9.  
Output:
Expand|Select|Wrap|Line Numbers
  1. >>> Something, by Spacecoyote
  2. YourFile.py file [options]
  3. This does not do anything
  4. options:
  5.   --version   show program's version number and exit
  6.   -h, --help  show this help message and exit
Jan 19 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Gregory (Grisha) Trubetskoy | last post by:
My humble $0.02: From http://www.python.org/doc/current/lib/optparse-terminology.html: The phrase "required option" is an oxymoron; the presence of "required options" in a program is usually a...
4
by: Sam Smith | last post by:
I am using optparse for the commandline parsing for my programs. I was wondering if it is possible to detect if an option or option-arg has been specified on the commandline by the user or not....
8
by: Hans-Joachim Widmaier | last post by:
I was really pleased when the Optik module found its way into the standard Python battery compartment, as it matched all my option parsing requirements. But, as always, there's really nothing that...
7
by: Henry Ludemann | last post by:
I've been writing an optparse alternative (using getopt) that is at a stage where I'd be interested in people's opinions. It allows you to easily creating command line interfaces to existing...
0
by: Steven Bethard | last post by:
I feel like I must be reinventing the wheel here, so I figured I'd post to see what other people have been doing for this. In general, I love the optparse interface, but it doesn't do any checks...
8
by: T | last post by:
I have a short program using optparse.OptionParser that prints out help message with -h flag: % myprog.py -h usage: myprog.py input_file options: -h, --help show this help...
4
by: rick | last post by:
Consider the following piece of code: parser = optparse.OptionParser(usage="usage: %prog <input filename> <output filename", add_help_option=False) parser.add_option("-d", type="string",...
4
by: Count László de Almásy | last post by:
Is there a standard way with optparse to include a blurb of text after the usage section, description, and the list of options? This is often useful to include examples or closing comments when...
10
by: James | last post by:
Hi, I would like to know your thoughts on a proposed change to optparse that I have planned. It is possible to add default values to multiple options using the set_defaults. However, when adding...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.