def set_x(option, opt, value, parser):
    parser.values.x = value
parser.values.x_set_explicitly = True
opts = OptionParser()
opts.add_option('-f', action='store_true')
opts.add_option('-x', dest='x', type='int', default=1, action='callback',
    callback=set_x)
options, args = opts.parse_args()
opts.values.ensure_value('x_set_explicitly', False)
if options.x_set_explicitly and options.f:
    opts.error('options -x and -f are mutually exclusive')
Python optparse, default values, and explicit options