Next / Previous / Contents / Shipman's homepage

20.10. InputFile.__delBlankCols(): Suppress entirely blank columns

listext2
# - - -   I n p u t F i l e . _ _ d e l B l a n k C o l s

    def __delBlankCols(self):
        '''Remove any columns that are entirely blank.

          [ self.__blockList is as invariant ->
              self.__blockList  :=  self.__blockList minus any columns
                  that contain only empty or entirely blank lines
              self.nOutLines  +:=  number of output lines remaining
                  after removal of blank columns
              self.nOverflows  +:=  number of overflow lines remaining
                  after removal of blank columns
              self.nOutCols  +:=  number of columns remaining
                  after removal of blank columns ]              
        '''

Now that the column breaks are marked, we go through the entire list of blocks and test each column to see if there are any nonblank lines in that column. For each nonblank column, the blocks are appended to newList, and the various counts are incremented.

listext2
        #-- 1
        newList = []

Section 20.11, “InputFile.__genCols(): Find the columns in the block list” is a generator that generates pairs of indices that bracket the columns in self.__blockList. For the logic that checks all the blocks in a given range, see Section 20.12, “InputFile.__anyNonblank(): Does this column contain any nonblank lines?”.

listext2
        #-- 2
        # [ newList  +:=  blocks from self.__blockList that occur in
        #       columns with at least one nonblank line
        #   self.nOutCols  +:=  columns in self.__blockList that
        #       contain at least one nonblank line        
        #   self.nOutLines  +:=  number of such blocks
        #   self.nOverflows  +:=  number of such blocks that are
        #       OverflowBlock instances ]
        for fromx, tox in self.__genCols():
            #-- 2 body
            # [ 0 <= fromx < tox <= len(self.__blockList) ->
            #     if self.__blockList[fromx:tox] are all blank ->
            #       I
            #     else ->
            #       newList  +:=  self.__blockList[fromx:tox]
            #       self.nOutLines  +:=  (tox-fromx)
            #       self.nOverflows  +:=  number of lines in
            #           self.__blockList[fromx:tox] that are instances
            #           of OverflowBlock ]
            if self.__anyNonblank(fromx, tox):
                self.nOutCols += 1
                for blox in range(fromx, tox):
                    block = self.__blockList[blox]
                    newList.append(block)
                    self.nOutLines += 1
                    if isinstance(block, OverflowBlock):
                        self.nOverflows += 1

Finally, replaced the original block list with the filtered version.

listext2
        #-- 3
        self.__blockList = newList