parser.add_option('-q', '--query', action='store', dest='query', help=
    'query string', default='spam')
options, args = parser.parse_args()
print('Query string:', options.query)
Most pythonic way of accepting arguments using optparse