class_docstr: A simple framework for writing line-oriented command interpreters.
  
  These are often useful for test harnesses, administrative tools, and
  prototypes that will later be wrapped in a more sophisticated interface.
  
  A Cmd instance or subclass instance is a line-oriented interpreter
  framework.  There is no good reason to instantiate Cmd itself; rather,
  it's useful as a superclass of an interpreter class you define yourself
  in order to inherit Cmd's methods and encapsulate action methods.
class_docstr_tok: ["A","simple","framework","for","writing","line-oriented","command","interpreters",".","These","are","often","useful","for","test","harnesses",",","administrative","tools",",","and","prototypes","that","will","later","be","wrapped","in","a","more","sophisticated","interface",".","A","Cmd","instance","or","subclass","instance","is","a","line-oriented","interpreter","framework",".","There","is","no","good","reason","to","instantiate","Cmd","itself",";","rather",",","it","'s","useful","as","a","superclass","of","an","interpreter","class","you","define","yourself","in","order","to","inherit","Cmd","'s","methods","and","encapsulate","action","methods","."]
docstr: Display a list of strings as a compact set of columns.
  
  Each column is only as wide as necessary.
  Columns are separated by two spaces (one was not legible enough).
docstr_tok: ["Display","a","list","of","strings","as","a","compact","set","of","columns",".","Each","column","is","only","as","wide","as","necessary",".","Columns","are","separated","by","two","spaces","(","one","was","not","legible","enough",")","."]
code: def columnize(self, list, displaywidth=80):
      """Display a list of strings as a compact set of columns.
  
      Each column is only as wide as necessary.
      Columns are separated by two spaces (one was not legible enough).
      """
      if not list:
          self.stdout.write("<empty>\n")
          return
  
      nonstrings = [
          i for i in range(len(list)) if not isinstance(list[i], str)
      ]
      if nonstrings:
          raise TypeError(
              "list[i] not a string for i in %s"
              % ", ".join(map(str, nonstrings))
          )
      size = len(list)
      if size == 1:
          self.stdout.write("%s\n" % str(list[0]))
          return
      # Try every row count from 1 upwards
      for nrows in range(1, len(list)):
          ncols = (size + nrows - 1) // nrows
          colwidths = []
          totwidth = -2
          for col in range(ncols):
              colwidth = 0
              for row in range(nrows):
                  i = row + nrows * col
                  if i >= size:
                      break
                  x = list[i]
                  colwidth = max(colwidth, len(x))
              colwidths.append(colwidth)
              totwidth += colwidth + 2
              if totwidth > displaywidth:
                  break
          if totwidth <= displaywidth:
              break
      else:
          nrows = len(list)
          ncols = 1
          colwidths = [0]
      for row in range(nrows):
          texts = []
          for col in range(ncols):
              i = row + nrows * col
              if i >= size:
                  x = ""
              else:
                  x = list[i]
              texts.append(x)
          while texts and not texts[-1]:
              del texts[-1]
          for col in range(len(texts)):
              texts[col] = texts[col].ljust(colwidths[col])
          self.stdout.write("%s\n" % str("  ".join(texts)))
  
file_path: catboost/contrib/tools/python3/src/Lib/cmd.py
imports: import string, sys
label_desc: Use image node_id 18 for calling the Cmd obj's underlying member method code with example usage: obj.columnize(list, displaywidth) without return types