code: def guess_width(self):
          
          if len(self.header) <= 4:
              nspace = 6
          elif len(self.header) <= 6:
              nspace = 5
          else:
              nspace = 4
          ncol = len(self.header)
          self._width = [nspace] * ncol
          width = [0] * ncol
  
          # set initial width from header
          for idx, item in enumerate(self.header):
              width[idx] = len(str(item))
  
          # guess width of each column from first 10 lines of data
          samples = min(len(self.data), 10)
          for col in range(ncol):
              for idx in range(samples):
                  data = self.data[idx][col]
                  if not isinstance(data, (float, int)):
                      temp = len(data)
                  else:
                      temp = 10
                  if temp > width[col]:
                      width[col] = temp
  
          for col in range(ncol):
              self._width[col] += width[col]
docs: auto fit column width