Hi,
I'm having some minor problems with optparse. I'm just worried that
someone shouldn't say that multiple argument feature isn't implemented
in optpartse.
How to tackle multiple arguments to an option ?
As far as I dug, I've found that >1 arguments are being ignored.
parser.add_option("", "--my-option", dest="my_option", action="store",
type="string")
Now if someone uses it as:
../foo --my-option a b c
I want somehow to store all the three arguments but my_option stores
only "a" while ignoring b and c.
Any help?
Ritesh 8 9912
Ritesh Raj Sarraf wrote: Hi,
I'm having some minor problems with optparse. I'm just worried that someone shouldn't say that multiple argument feature isn't implemented in optpartse.
How to tackle multiple arguments to an option ? As far as I dug, I've found that >1 arguments are being ignored.
parser.add_option("", "--my-option", dest="my_option", action="store", type="string")
Now if someone uses it as: ./foo --my-option a b c
I want somehow to store all the three arguments but my_option stores only "a" while ignoring b and c.
I just noticed that the args variable is holding values b and c.
the args variables comes from:
(options, args) = parser.parse_args()
I guess I only need to figure out now is why args isn't storing
argument "a" also...
Ritesh
Ritesh Raj Sarraf wrote: I just noticed that the args variable is holding values b and c. the args variables comes from: (options, args) = parser.parse_args()
I guess I only need to figure out now is why args isn't storing argument "a" also...
Ritesh
I fixed it, I guess.
parser.add_option("", "--my-option", dest="my_option",
action="store_true")
sets my_option to True and the arguments are all stored in the list
"args". :-)
Ritesh
Ritesh Raj Sarraf wrote: I guess I only need to figure out now is why args isn't storing argument "a" also...
I fixed it, I guess.
parser.add_option("", "--my-option", dest="my_option", action="store_true")
sets my_option to True and the arguments are all stored in the list "args". :-)
note that whatever action you're using, args holds the *remaining* arguments, after
option processing.
</F>
Ritesh Raj Sarraf wrote: Ritesh Raj Sarraf wrote: I just noticed that the args variable is holding values b and c. the args variables comes from: (options, args) = parser.parse_args()
I guess I only need to figure out now is why args isn't storing argument "a" also...
Ritesh
I fixed it, I guess.
parser.add_option("", "--my-option", dest="my_option", action="store_true")
sets my_option to True and the arguments are all stored in the list "args". :-)
Ritesh
It might do you good to read the documentation instead of blindly
experimenting.
Anyway,
parser.add_option("", "--my-option", nargs=3) http://docs.python.org/lib/optparse-...n-actions.html
Simon Percivall wrote: It might do you good to read the documentation instead of blindly experimenting.
Anyway,
parser.add_option("", "--my-option", nargs=3)
http://docs.python.org/lib/optparse-...n-actions.html
That won't help because by design of my program, I can't limit the
number of arguments a user can pass to it.
Ritesh
Fredrik Lundh wrote: Ritesh Raj Sarraf wrote:
http://docs.python.org/lib/optparse-...n-actions.html
That won't help because by design of my program, I can't limit the number of arguments a user can pass to it.
do you want options, arguments, or are you just somewhat confused ?
</F>
I'm not sure about that.
My program will accept user input. The user can input multiple
arguments. maybe 1 or maybe 100, that's not definite. I do need option
because this particular (multiple) argument criteria is for one single
option.
Thanks,
Ritesh
Ritesh Raj Sarraf wrote: Now if someone uses it as: ./foo --my-option a b c
I want somehow to store all the three arguments
Currently optparse doesn't support options with an arbitrary number of
arguments. I'm currently working on a optparse-inspired replacement
which does support this along the lines of:
parser.add_option('--my-option', nargs='*')
but it's not quite ready for prime-time yet. I'm hoping to put an
announcement out in the next couple of weeks.
STeVe This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
by: Tomi Silander |
last post by:
Hi,
this must have been asked 1000 times (or nobody is as stupid as me),
but since I could not find the answer, here is the question.
My program mitvit.py:
--------------
import optparse...
|
by: Bob |
last post by:
I'd like to setup command line switches that are dependent on other
switches, similar to what rpm does listed below. From the grammar below
we see that the "query-options" are dependent on the...
|
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...
|
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",...
|
by: Mathias Waack |
last post by:
We've integrated python into a legacy application. Everything works fine (of
course because its python;). There's only one small problem: the
application reads the commandline and consumes all...
|
by: braver |
last post by:
Posted to the Optik list, but it seems defunct. Optik is now Python's
optparse.
I wonder how do you implement optional arguments to Optik. I.e., you
can have an option
-P
-- the...
|
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...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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
|
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...
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |