Next / Previous / Contents / TCC Help System / NM Tech homepage

14.9. PickList.__convert8(): Convert an 8-bit number

This method is used to process one of the 8-bit numbers from the rgb.txt file.

huey
# - - -   P i c k L i s t . _ _ c o n v e r t 8

    def __convert8 ( self, s ):
        """Convert a string to an 8-bit number.

          [ if s is the string representation of a number in
            [0,255] ->
              return s as an integer
            else -> raise IOError ]
        """
        #-- 1 --
        # [ if s can be converted to an integer ->
        #     result  :=  s converted to an integer
        #   else -> raise IOError ]
        try:
            result  =  int ( s )
        except ValueError:
            raise IOError, "Bad color value: '%s'" % s

        #-- 2 --
        return result