I have several optional arguments and one of them needs to store multiple values - i.e. its type is neither string nor integer. Does argparse support optional arguments of other types?
For example, I would like this command:
>>> python example1 test_project --name try1 3
to be the equivalent of code like this:
args.name = {'try1', '3'}
Is this possible? Or will I be forced to use action='store_true'
and then prompt the user for more information if he choose this option?
I'm really having a hard time following your question. Is this what you want?
import argparse
parser=argparse.ArgumentParser()
parser.add_argument('--name',nargs='*',action='store')
print(parser.parse_args('--name try1 3'.split())) #Namespace(name=['try1', '3'])
If it isn't, perhaps you could try to be a little more clear with what you want to make argparse do, and what you've been able to do with it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With