-1

I'm writing a script in python and I need to do something like this:

python myscript.py command1 --commandarg1 --commandarg2

python myscript.py --scriptargument1 --scriptargument2 command2 --commandarg1 --commandarg2 --commandarg3

Is this possible using argparse?

IAmJulianAcosta
  • 1,082
  • 2
  • 14
  • 30
  • https://docs.python.org/2/howto/argparse.html – Alexander Jul 27 '16 at 22:51
  • 3
    Possible duplicate of [Dead simple argparse example wanted: 1 argument, 3 results](http://stackoverflow.com/questions/7427101/dead-simple-argparse-example-wanted-1-argument-3-results) – idjaw Jul 27 '16 at 22:52
  • "Is this possible using `argparse`?". [Yes](https://docs.python.org/2/library/argparse.html#sub-commands). Argparse calls these `subcommands` (which are parsed by "subparsers") – mgilson Jul 27 '16 at 23:15
  • @mgilson please add it as an answer, that is what I'm looking for – IAmJulianAcosta Jul 27 '16 at 23:28

1 Answers1

1

Yes the argparse module is exactly that what you are looking for.

visit this page to get the informations how to work with it:

https://docs.python.org/3/library/argparse.html

Melody
  • 182
  • 2
  • 12