Hello,
is there a python library available for handling GNU parameters. For
example:
prog --filename=foo.bar is the same as prog -f foo.bar
or
prog --execute == prog -e
I look for a library for parsing these string and represent the values in a
list.
Thx,
Florian 5 1425
Florian Lindner wrote: is there a python library available for handling GNU parameters. For example:
prog --filename=foo.bar is the same as prog -f foo.bar
or
prog --execute == prog -e
I look for a library for parsing these string and represent the values in a list.
The standard library module getopt can do that, at least for the sort
of example you show, and I suspect the newer standard library module
optparse could also handle it (but haven't tried myself).
-Peter
Peter Hansen a écrit : Florian Lindner wrote:
is there a python library available for handling GNU parameters. For example:
prog --filename=foo.bar is the same as prog -f foo.bar
or
prog --execute == prog -e
I look for a library for parsing these string and represent the values in a list.
The standard library module getopt can do that, at least for the sort of example you show, and I suspect the newer standard library module optparse could also handle it (but haven't tried myself).
-Peter
Standard Module optparse http://www.python.org/doc/2.3.3/lib/...-optparse.html
Note that if you do not have python2.3 you can just put the optparse.py
and put it in you python2.2 directory, it will work !
--
Yermat
[Peter Hansen] The standard library module getopt can do that, at least for the sort of example you show, and I suspect the newer standard library module optparse could also handle it (but haven't tried myself).
I think I read that `optparse' is not going to handle optional arguments
that we find in some commands, and which GNU `getopt' (and also the old
standard `getopt', if I remember well) do handle. As this is a design
choice for `optparse', it might never fully replace `getopt'.
--
François Pinard http://www.iro.umontreal.ca/~pinard
François Pinard wrote: I think I read that `optparse' is not going to handle optional arguments that we find in some commands,
Do you mean "optional option arguments"? Where an option has an
optional argument? I believe this idea was discussed on the
optik-users list, but it was determined that such a thing is not
reliably parseable.
and which GNU `getopt' (and also the old standard `getopt', if I remember well) do handle.
getopt.py does *not* handle "optional option arguments" either.
If you meant optional positional arguments, optparse and getopt both
support them (by leaving the logic up to the client program).
-- David Goodger
[David Goodger] Do you mean "optional option arguments"? Where an option has an optional argument?
Within GNU `getopt', it is requested by a double colon after an
option letter in the option string, and with the predefined constant
`optional_argument' in the second position of a `struct option'
entry (the two other predefined constants being `no_argument' and
`required_argument').
I believe this idea was discussed on the optik-users list, but it was determined that such a thing is not reliably parseable.
GNU `getopt' parses it. Yet, users have to be careful while providing
the optional value, for complying with the rules. About if this is the
parser, or the user, not being reliable, is a debatable question :-).
getopt.py does *not* handle "optional option arguments" either.
I noticed. When I translated Recode to Python, I had to devise a stunt
around this limitation.
If you meant optional positional arguments, optparse and getopt both support them (by leaving the logic up to the client program).
:-) :-). By leaving the logic up to the client program, every module
could be said to support every thinkable feature! This is not exactly
what we usually mean by "support"! :-)
--
François Pinard http://www.iro.umontreal.ca/~pinard This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Chris Fonnesbeck |
last post by:
I thought I knew how to do error handling in python, but apparently I
dont. I have a bunch of code to calculate statistical likelihoods, and
use error handling to catch invalid parameters. For...
|
by: Steve Jorgensen |
last post by:
When writing VB or VBA code that works with databases or other external
libraries that cannot be trusted to automatically do the right thing when
references to their objects are arbitrarily...
|
by: TJ |
last post by:
In C# how do you achieve pass-by-reference property declarations in the Type
Library?
I am writing a COM Class Library that must mimick an existing library for
which the only information is the...
|
by: dhussong |
last post by:
I'm trying to implement a generic exception handling routine that will write
information to a text file at the time the exception occurred. I am using the
Microsoft Application Block for Exception...
|
by: Mr Newbie |
last post by:
I am often in the situation where I want to act on the result of a function,
but a simple boolean is not enough. For example, I may have a function
called
isAuthorised ( User, Action ) as ?????...
|
by: dgiagio |
last post by:
Hi,
I'm creating a SMTP application and I would like to hear opinions about
error handling. Currently there are two functions that communicate with
the remote peer:
ssize_t...
|
by: jacob navia |
last post by:
Recently, Microsoft proposed to the C standards comitee a rewrite of
many functions in the standard library to make them safer in usage than
the current ones.
The new functions are specified in...
|
by: csgraham74 |
last post by:
Hi guys,
Basically i have been developing in dotnet for a couple of years but
ive had a few issues in regards to error handling.
For example - I have a class that i call passing in a stored...
|
by: J de Boyne Pollard |
last post by:
MThe library functions which are included to allow process
Mlaunch, forking, and termination, imply that it is both
Mpossible and desirable for a process to fork itself. This is
Ma fundamental...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |