How to use getopt/optarg in Python?
Have you tried reading the python docs for the module getopt
(http://docs.python.org/library/getopt.html?highlight=getopt#module-getopt)? It provides a simple example of how the getopt
is used. What do you mean by shift arguments? If you want to check that the user does not use more than 9 arguments, you can check the length of the sys.argv
list, which contains all the options/arguments passed to the script. The first element is the name of the script which is invoked, so the length is always at least 1. You could do something like:
if len(sys.argv) > 10
print('Too many arguments.')