optparse TypeError

Michele Simionato michele.simionato at gmail.com
Mon Jun 28 23:31:53 EDT 2010


On Jun 28, 11:47 pm, rantingrick <rantingr... at 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.



More information about the Python-list mailing list