473,320 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Library for handling GNU parameters

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
Jul 18 '05 #1
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
Jul 18 '05 #2
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

Jul 18 '05 #3
[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

Jul 18 '05 #4
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

Jul 18 '05 #5
[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

Jul 18 '05 #6

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

Similar topics

2
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...
2
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...
7
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...
3
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...
14
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 ?????...
3
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...
3
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...
5
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...
20
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...
0
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
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...
0
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...
0
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...
0
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...
1
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)...
1
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....
0
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...

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.