473,624 Members | 2,502 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Required options in optparse


My humble $0.02:

From http://www.python.org/doc/current/li...minology.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
be an oxymoron as far as English is concerned, I think a more accurate
assessment is that "option" is a misnomer, because there is nothing wrong
with requiring one.

Here is an example from a fictional database program. Imagine that to
craete a database I have to specify a name, db size and a some kind of a
device id (the two latter both being integers):

usage: initdb dbname -s size -d dev_id [-t dbtype]

e.g.:

$ initdb mydb -s 1024 -d 1010

Arguably, dbname, size and dev_id could be specified as required
positional _arguments_, but it would be less clear and more error-prone:

usage: initdb dbname size dev_id [-t dbname]

e.g.:

$ initdb mydb 1024 1010

Therefore, I think "required options" should be part of OptionParser.

Anyone disagree?

Grisha
Jul 18 '05 #1
0 1568

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2163
by: Chris | last post by:
I'm trying to come up with a not-so-ugly manner of passing many command-line options between modules. I have a Steering.py file, which contains my main() and handles the getopts getting of several command-line options. Since having 5-6 additional parameters for every class instantiation or function call is obviously an ugly way to handle this, what would you folks recommend as a superior option? Maybe passing a dict of options to each...
7
2783
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,...
5
2238
by: Norbert Thek | last post by:
Hi I'm using Python 24 on Windows > (2k) Is there an easy way to convince optparse to accept newline in the helpstring? and more importand also in the 'desc' string. I tried everything (from the os.linesep) to \n, \r, \r\n, ... Norbert
3
2452
by: Karlo Lozovina | last post by:
If I create a file with only one line: --- from optparse import OptionParser --- I get this when I try to run it from "DOS" prompt: Traceback (most recent call last): File "optparse.py", line 1, in ?
7
1537
by: Leo Breebaart | last post by:
I have another question where I am not so much looking for a solution but rather hoping to get some feedback on *which* solutions people here consider good Pythonic ways to approach a issue. The situation is this: I am writing fairly large console scripts in Python. They have quite a few command-line options, which lead to configuration variables that are needed all over the program (e.g. the "--verbose" option alone is used by just...
0
1134
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
3501
by: Andrew Robert | last post by:
Hi Everyone. I tried the following to get input into optionparser from either a file or command line. The code below detects the passed file argument and prints the file contents but the individual swithces do not get passed to option parser.
3
1941
by: Rocky Zhou | last post by:
I wonder is there any way to make the wrapper program can wrap options && arguments for the the subprocess/command the wrapper will execute? by getopt or optparse module? This is something like the shell script like this: optwrap="" while ; do case $1 in -a) do-something; shift ;;
0
1029
by: Benny the Guard | last post by:
I have become familiar with optparse code to parse various options into a program. But right now having some difficulties with a new project I am working on (not a class project, just a new script). What I need is a command line util that can take various flags, these are 100% inclusive with no overlap. Easy, but now I want to also create some super-flags that setup a bunch of different values, and are exclusive to other super-flags. So for...
0
8246
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8179
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
8685
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
8631
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
8490
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...
0
7174
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4084
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...
1
2612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1489
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.