Next / Previous / Contents / Shipman's homepage

18.4. Args._checkPoints(): Check the font size option

listext2
# - - -   A r g s . _ c h e c k P o i n t s

    def _checkPoints(self, rawValue):
        '''Require an integer >= 5.

          [ rawValue is a str ->
              if rawValue represents an int >= 5 ->
                return that value as an int
              else -> raise argparse.ArgumentTypeError ]
        '''
        #-- 1
        # [ if rawValue can be converted to int ->
        #     return rawValue converted to int
        #   else -> raise argparse.ArgumentTypeError ]
        try:
            value = int(rawValue)
        except ValueError:
            raise argparse.ArgumentTypeError("Must be "
                "an integer, 5 or greater.")

        #-- 2
        if value < 5:
            raise argparse.ArgumentTypeError("Must be "
                "5 or greater.")
        else:
            return value