title: make a test python options mandatory
body: <p>I am using getopt to get the options from command line. How can I check if an option has been set or not. I have tried by setting a value to 1 and test it and it works but I was wondering if there is another way to do it?</p>
  
  <pre><code>def main(argv):
      inputfile = ''
      outputfile = ''
      i = 0
      o = 0
      d = 0
      usage = """
  Usage:  rotate.py [OPTIONS] ...
      rotate.py -i img1.jpg -o img2.py -d 10
      rotate.py -i img1.jpg -d 10
  
      -h --help               Display this usage message
      -i --ifile &lt;inputfile&gt;          The file to rotate
      -o --ofile &lt;outputfile&gt;         The file that will have the rotated image.
      -d --degres &lt;integer&gt;           The number of degres to rotate
  """
      try:
          opts, args = getopt.getopt(argv,"hi:o:d:",["ifile=","ofile=","degres=","help"])
      except getopt.GetoptError:
          print usage
          sys.exit(2)
      for opt, arg in opts:
          if opt in ("-h", "--help"):
              print usage
              sys.exit()
          elif opt in ("-i", "--ifile"):
              inputfile = arg
              i = 1
          elif opt in ("-o", "--ofile"):
              outputfile = arg
              o = 1
          elif opt in ("-d", "--degres"):
              degres = arg
              d = 1
      if (inputfile in globals()) &amp; (outputfile in globals()) &amp; (degres in globals()):
          rotate_picture(inputfile, outputfile, degres)
      elif (inputfile in globals()) &amp; (degres in globals()):
          rotate_picture(inputfile, inputfile, degres)
      else:
          print usage
  
  if __name__ == "__main__":
     main(sys.argv[1:])
  </code></pre>