parser = OptionParser(usage='usage: %prog [options] arguments')
parser.add_option('-f', '--file', dest='filename')
options, args = parser.parse_args()
if 'filename' not in options.__dict__:
    parser.error('Filename not given')
Python: How to make an option to be required in optparse?