Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comma separated inputs instead of space separated inputs for argparse

I'm using argparse to receive inputs from the command line to run my script.

My current input string looks like this:

path> python <\filename\\> -t T1 T2 T3 -f F1 F2

Is there a parameter in argparse such that instead of separating inputs by space, I can separate them by commas?

In other words:

path> python <\filename\\> -t T1,T2,T3 -f F1,F2
like image 765
Campo21 Avatar asked Feb 09 '18 21:02

Campo21


Video Answer


1 Answers

There is no such feature in argparse.

Alternatives:

  • post-process the args namespace and split/parse the values manually
  • define a custom action and split/parse the values manually
  • define a custom type and split/parse the values manually
  • subclass ArgumentParser and customise ArgumentParser.convert_arg_line_to_args
like image 151
wim Avatar answered Sep 21 '22 04:09

wim