Re: Positional arguments parsing

"Martin Blais" <[email protected]> Sat, 24 Jun 2006 19:23:57 -0400
Newsgroups gmane.comp.python.optik.user
Message-ID <[email protected]>
Too bad I was offline this afternoon, I could not check the web first;
  I dived in and implemented a similar thing as you did!  I am writing
so many scripts that it gets annoying to have to parse the args
manually everytime.

It would be REALLY nice if optparse provided this feature, either with
Diogo's implementation, mine, or anybody else's.

Anyway, for what it's worth, here is my version:
http://furius.dyndns.biz/pubcode/pub/conf/common/lib/python/optparse_wargs.py.html

Differences:

* You can specify how many arguments you want to consume, and -1 will
consume all the remaining arguments.  2 will consume two and return a
list.

* I store the results on the same object as the options.  This makes
sense because you will rarely assign the same target name for an
option and an argument and therefore there need not be collisions in
names -- the rationale is that the only difference between options and
arguments is that options are optional, and arguments are required
(except for the last conceptual "argument", which could be a list,
i.e. a list of filenames).  Also, an option can become an argument and
vice-versa during the lifetime of a program and using the same target
object makes it easier to change the source code afterwards.

* I do not support actions.  (this could be added though.)

* Mine has a perhaps simpler interface, more similar to optparse
(Diogo: why do you require passing in a list in your examples? Why not
just use varargs instead?)

I think it would make sense to reuse the type conversion and actions
that are already available for options in optparse.   (I assume
posparse does that.)

cheers,




PS example usage posted here:

import optparse_wargs as optparse
...

parser = optparse.OptionParserWithArgs(...)

...
parser.add_argument('dbname', 'The database name to work on.')
parser.add_argument('dumpfile', 'The dump file to work on.')

opts = parser.parse_args()

# Use opts.dbname, opts.dumpfile, ...







On 4/22/06, Diogo Kollross <[email protected]> wrote:
> I've made a module for positional arguments parsing, based on optparse:
>
>   http://geocities.com/diogok_br/posparse/
>
> I wonder if a similar feature is planned for Optik.
>
> --
> Diogo Kollross
>
>
> -------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmdlnk&kid0709&bid&3057&dat1642
> _______________________________________________
> optik-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/optik-users
>

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642