For example, if I give
test.py -a SOMETHING 1 2 3
after option parsing, I want two lists:
>> print opt
>> ['-a', 'SOMETHING']
>> print args
>> ['1', '2', '3']
Is it possible to do this using optparse?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Looking at the optparse documentation it seems like you can do this:
If I run this using your command line
python test.py -a SOMETHING 1, 2, 3it prints:which seems very close to the desired result.
If you really must have the options as a list, you could add something like this to the code above:
For me this prints: