From: Michele Simionato on
On Jun 28, 9:56 pm, Ben Finney <ben+pyt...(a)benfinney.id.au> wrote:
> Michele Simionato <michele.simion...(a)gmail.com> writes:
> > optparse is so old-fashioned. Use plac!
>
> The OP should be made aware that:
>
> * plac is a third-party library with (TTBOMK) no prospect of inclusion
>   in the standard library
>
> * optparse is in the standard library and has been for many versions
>
> * argparse is a third-party library that is now accepted for inclusion
>   in the standard library, intended as a full optparse replacement
>   <URL:http://www.python.org/dev/peps/pep-0389/>

All valid points. I will just add that plac is based on argparse and
nothing else, so it is an external dependency, yes, but not a large
dependency. Moreover the core is only 200 lines. People can just grab
http://micheles.googlecode.com/hg/plac/plac_core.py, and include it in
their personal code base, possibly adapting it (I mean for people
preferring recipes to external dependencies).

Michele Simionato
From: Michele Simionato on
On Jun 28, 11:47 pm, rantingrick <rantingr...(a)gmail.com> wrote:
> Give your *script* an
> enema, and do *yourself* a favor by harnessing the simplistic elegance
> of the "optphart" module instead!
>
> #-- Start Script --#
> def optphart(args):
>     d = {'args':[]}
>     for arg in args:
>         if arg.startswith('-'):
>             key, value = arg.split('=', 1)
>             options = value.split(',')
>             if len(options) > 1:
>                 d[key[1:]] = options
>             else:
>                 d[key[1:]] = [value]
>         else:
>             d['args'].append(arg)
>     return d

Probably I should not be answering this, but try to implement the
parsing required by the OP with this approach, including the
generation of the usage message and the error checking. Just try.

M. S.