I'm try to work out how to use optparse, but I've come to a problem.
My script (represented by this simplified example) takes a file, and does different things to it depending on options that are parsed to it. If no options are parsed nothing is done.
It makes sense to me that because of this, an error should be given if no options are given by the user. I can't work out how to do this.
I've read that options should be optional and not required. Does this mean I am using options in the wrong way? If so, how should I be doing it instead? I can't see any other way of going about it.
#!/usr/bin/python
from optparse import OptionParser
dict = {'name': foo, 'age': bar}
parser = OptionParser()
parser.add_option("-n", "--name", dest="name")
parser.add_option("-a", "--age", dest="age")
(options, args) = parser.parse_args()
if options.name:
dict['name'] = options.name
if options.age:
dict['age'] = options.age
print dict
#END