I tried this: - usage = "Something, by Spacecoyote\nusage: %prog file [options]"
-
parser = OptionParser(usage)
and I expected: - Something, by Spacecoyote
-
usage: test.py file [options]
but I got: - 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.
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. - 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: - >>> 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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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.
|
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...
|
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,...
|
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 =...
| |
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
|
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
|
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
|
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',
|
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,...
|
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...
| |
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...
|
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...
|
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...
|
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();...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |