473,789 Members | 2,500 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

optparse: usage

15 New Member
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 1998
bvdet
2,851 Recognized Expert Moderator Specialist
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
1577
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 sign of careless user interface design. optparse doesn't prevent you from implementing required options, but doesn't give you much help with it either. I don't know if I necessarily agree with this. While "required option" may
4
4010
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. Please do not suggest default value solutions. Thanks.
8
2311
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 does all you ever want, especially when it comes to option parsing - there's just too many schemes to handle them all comfortably. With this program I'm working on, I started to recognize that not only the functionality should be delegated to...
7
2792
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 functions, using flags (which are optional) and arguments. It will automatically print a nicely formatted usage (eg: -h or --help), and easily & automatically validates parameter existence and type. You can download it, and read a bit more about it,...
0
1138
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 on the arguments. I've coded something along the following lines a number of times: class OptionArgParser(optparse.OptionParser): def __init__(self, *args, **kwargs): self.min_args = kwargs.pop('min_args', None) self.max_args =...
8
3529
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 message and exit -v, --verbose print program's version number and exit -o FILE Output file
4
431
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", action="store", dest="DELIM", default="|", help="single character delimiter in quotes (default: |)") (options, args) = parser.parse_args() Is there any way I can add help for the arguments (<input filenameand
4
3490
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 the help message is printed out. Many of the GNU commands do this. It would look something like this: % program --help usage: program
10
1431
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 descriptions to options the developer has to specify it in each add_option() call. This results in unreadable code such as: parser.add_option('-q', '--quiet' , action="store_false", dest='verbose',
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10404
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10195
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6765
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.