Next / Previous / Contents / Shipman's homepage

10. Truths.__init__()

tracecase
# - - -   T r u t h s . _ _ i n i t _ _

    def __init__ ( self, lineList ):
        '''Constructor
        '''

We can eliminate one error case right away: suppose the input was empty? What would be the point of such an input stream? This is probably an error.

tracecase
        #-- 1
        if len(lineList) == 0:
            raise ValueError("The input was empty.")

Each call to Section 11, “Truths._lineCheck(): Check one input line” attempts to parse one input line and, if successful, adds the string of that row of truth values to self._condList.

tracecase
        #-- 2
        self._condList = []

        #-- 3
        # [ if all elements of lineList are valid input lines ->
        #     self._condList  +:=  strings containing the uppercased
        #         truth values from lineList in the same order
        #   else -> raise ValueError ]
        for line in lineList:
            #-- 3 body
            # [ if line is a valid input line ->
            #     self._condList  +:=  a string containing the
            #         uppercased truth values from line
            #   else -> raise ValueError ]
            self._lineCheck(line)

Finally, check to be sure that each line has the same number of codes.

tracecase
        #-- 4
        # [ if any two lines in self._condList have different
        #   lengths ->
        #     raise ValueError
        #   else -> I ]
        len0 = len(self._condList[0])
        for linex in range(1, len(self._condList)):
            lenK = len(self._condList[linex])
            if len0 != lenK:
                raise ValueError("Line {linex} has {lenK} codes, "
                    "but the first line has {len0} codes.".format(
                    linex=linex, lenK=lenK, len0=len0))

        #-- 5
        self._caseCount = len0