The args
return value of parse_args
is the "the leftover positional arguments after all options have been processed" (http://docs.python.org/2/library/optparse.html#parsing-arguments). It parsed all the arguments you gave it, so there is nothing left to put in args.
If you run, for example,
script.py -z hello.zip -d world.txt foo bar
then 2
will be printed.
P.S. As @Michael0x2a pointed out in a comment, the optparse
library is deprecated. Take a look at the argparse library.