I've been studying a little bit of Python and I came across the getopt
module for parsing command-line arguments.
Basically, I've got the following code:
import sys, getopt
print("The list of %s arguments passed:" % len(sys.argv))
# Print each argument
for arg in sys.argv:
print(arg)
print()
# Now print parsed arguments
opts, args = getopt.getopt(sys.argv[1:], "ab:cd", ["arbitrary", "balance=", "cite"])
for opt in opts:
print(opt)
print()
# Print the arguments returned
print(args)
However, I need the -b
option to take two different arguments, E.g -b one two
. I've tried putting two colons after the b
in the argument list of getopt
, but it didn't work.
If someone can tell me how to do this using the getopt
module and post examples it would be really useful!