Staging
v0.5.1
https://github.com/python/cpython
Raw File
Tip revision: 624af829a7d930d29f359c3d8a2408efc36b34e8 authored by Trent Mick on 19 June 2006, 23:57:41 UTC
[ 1295808 ] expat symbols should be namespaced in pyexpat
Tip revision: 624af82
required_1.py
import optparse

class OptionParser (optparse.OptionParser):

    def check_required (self, opt):
        option = self.get_option(opt)

        # Assumes the option's 'default' is set to None!
        if getattr(self.values, option.dest) is None:
            self.error("%s option not supplied" % option)


parser = OptionParser()
parser.add_option("-v", action="count", dest="verbose")
parser.add_option("-f", "--file", default=None)
(options, args) = parser.parse_args()

print "verbose:", options.verbose
print "file:", options.file
parser.check_required("-f")
back to top