home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 14 / hacker14.iso / programacao / pythonwin / python.exe / PYTHON23.CHM / lib / required_1.txt < prev    next >
Encoding:
Text File  |  2003-10-02  |  557 b   |  21 lines

  1. import optparse
  2.  
  3. class OptionParser (optparse.OptionParser):
  4.  
  5.     def check_required (self, opt):
  6.       option = self.get_option(opt)
  7.  
  8.       # Assumes the option's 'default' is set to None!
  9.       if getattr(self.values, option.dest) is None:
  10.           self.error("%s option not supplied" % option)
  11.  
  12.  
  13. parser = OptionParser()
  14. parser.add_option("-v", action="count", dest="verbose")
  15. parser.add_option("-f", "--file", default=None)
  16. (options, args) = parser.parse_args()
  17.  
  18. print "verbose:", options.verbose
  19. print "file:", options.file
  20. parser.check_required("-f")
  21.