optparse multiple arguments

Ritesh Raj Sarraf riteshsarraf at gmail.com
Fri Jun 30 04:53:54 EDT 2006


Ritesh Raj Sarraf wrote:
> Hi,
>
> I'm having some minor problems with optparse. I'm just worried that
> someone shouldn't say that multiple argument feature isn't implemented
> in optpartse.
>
> How to tackle multiple arguments to an option ?
> As far as I dug, I've found that >1 arguments are being ignored.
>
> parser.add_option("", "--my-option", dest="my_option", action="store",
> type="string")
>
> Now if someone uses it as:
> ./foo --my-option a b c
>
> I want somehow to store all the three arguments but my_option stores
> only "a" while ignoring b and c.
>

I just noticed that the args variable is holding values b and c.
the args variables comes from:
(options, args) = parser.parse_args()

I guess I only need to figure out now is why args isn't storing
argument "a" also...

Ritesh




More information about the Python-list mailing list