0
option_list = [
    make_option("-i", "--adapter", action="store",
        type="string", dest="dev_id"),
    make_option("-b", "--device", action="store",
        type="string", dest="address"),
            ]
parser = OptionParser(option_list=option_list)
(options, args) = parser.parse_args()

In the above code snippet, what value does args contain?

  1. when I try to print len(args), I am getting 0 even though I am passing 2 arguments via command line
  2. when I try to print just args it just prints [].

what actually is the use of that parameter and what does it contain?

glglgl
  • 89,107
  • 13
  • 149
  • 217
Jyothi
  • 21
  • 4

1 Answers1

1

Per the documentation:

parse_args() returns two values:

  • options, an object containing values for all of your options—e.g. if --file takes a single string argument, then options.file will be the filename supplied by the user, or None if the user did not supply that option
  • args, the list of positional arguments leftover after parsing options

In your case, len(args) == 0 because all of the arguments you pass are parsed into options.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437