programs always need arguments to make itself smarter to users. a program may
need the user’s choice when run foreground or background.
so it’s useful to add the arguments to your program.
when you using python language, you can find the doc in the official site, but
trust me that you may get confused even you follow the document.
here is the flow of my study and tricks.
let’s start with a simple example:
when you start your program you may get this:
very easy, or right, but it’s not always come to your thoughts when using python.
here we start to use sub module. supposing that we have a program can take:
- update
- download
- transfer
- delete
here we need arguments in the subcommands, we may define our argument like this:
there seem no problem here, but when you start run the script, you may find it
not work as you think.
why we make the -q the first level argument, it’s equal to a and b, but when we
get -q why does the argparse tell us too few arguments?
so here i just tell you about that:
- if you want your first level flag work with your subcommand, you just add all
the argurments and parse them at final step.
- if you want to make your first level arguments work at the same weight with
your subcommands, you need to get them out first and then.
let’s talk with second situation:
that’s all I know about if you want to see more, you need to refer the docs.
reference