Parsing cmd line args problem

Paulo da Silva psXdaXsilva at esotericaX.ptX
Fri Apr 9 23:04:21 EDT 2004


Paulo da Silva wrote:
I got it to work! Is there a better way?
> Hi.
> 
> I am writing my 1st. python program and I have the following problem:
> 
> I need to build a list of lists (or tuples) for every -i option.
> Example:
>     prog -i xxx -i yyy
>     and get a list like [[xxx,1],[yyy,1]]
> 
> I have tried this (callback) without any success:
> 
> ....
Here is what I did!
> def ixOpt(option,opt,value,parser):
      if parser.values.ix is None:
          parser.values.ix=[]
      parser.values.ix.append([value,1])
> 
> def parseArgs():
> ....
>     add_option("-i", "--include",
>                 action="callback",callback=ixOpt,
>                 type="string",dest="ix",
>                 help="Include file PATTERN",metavar="PATTERN")
> 
> Any help please?
> Thanks



More information about the Python-list mailing list