nodes: 0, module; 1, function_definition; 2, function_name:sort; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, function_definition; 11, expression_statement; 12, comment:# Exclude header by copying table.; 13, expression_statement; 14, if_statement; 15, expression_statement; 16, comment:# Regenerate the table with original header; 17, expression_statement; 18, expression_statement; 19, comment:# Re-write the 'row' attribute of each row; 20, for_statement; 21, identifier:cmp; 22, None; 23, identifier:key; 24, None; 25, identifier:reverse; 26, False; 27, comment:"""Sorts rows in the texttable.
  
      Args:
        cmp: func, non default sort algorithm to use.
        key: func, applied to each element before sorting.
        reverse: bool, reverse order of sort.
      """; 28, function_name:_DefaultKey; 29, parameters; 30, block; 31, assignment; 32, assignment; 33, comparison_operator:cmp is not None; 34, block; 35, call; 36, assignment; 37, call; 38, pattern_list; 39, call; 40, block; 41, identifier:value; 42, expression_statement; 43, expression_statement; 44, for_statement; 45, return_statement; 46, identifier:key; 47, boolean_operator; 48, identifier:new_table; 49, subscript; 50, identifier:cmp; 51, None; 52, expression_statement; 53, attribute; 54, argument_list; 55, attribute; 56, list; 57, attribute; 58, argument_list; 59, identifier:index; 60, identifier:row; 61, identifier:enumerate; 62, argument_list; 63, expression_statement; 64, comment:"""Default key func is to create a list of all fields."""; 65, assignment; 66, identifier:key; 67, attribute; 68, comment:# Try sorting as numerical value if possible.; 69, block; 70, identifier:result; 71, identifier:key; 72, identifier:_DefaultKey; 73, attribute; 74, slice; 75, assignment; 76, identifier:new_table; 77, identifier:sort; 78, keyword_argument; 79, keyword_argument; 80, identifier:self; 81, identifier:_table; 82, attribute; 83, attribute; 84, identifier:extend; 85, identifier:new_table; 86, attribute; 87, assignment; 88, identifier:result; 89, list; 90, identifier:self; 91, identifier:header; 92, try_statement; 93, identifier:self; 94, identifier:_table; 95, integer:1; 96, identifier:key; 97, call; 98, identifier:key; 99, identifier:key; 100, identifier:reverse; 101, identifier:reverse; 102, identifier:self; 103, identifier:header; 104, identifier:self; 105, identifier:_table; 106, identifier:self; 107, identifier:_table; 108, attribute; 109, identifier:index; 110, block; 111, except_clause; 112, identifier:cmp_to_key; 113, argument_list; 114, identifier:row; 115, identifier:row; 116, expression_statement; 117, identifier:ValueError; 118, block; 119, identifier:cmp; 120, call; 121, expression_statement; 122, attribute; 123, argument_list; 124, call; 125, identifier:result; 126, identifier:append; 127, call; 128, attribute; 129, argument_list; 130, identifier:float; 131, argument_list; 132, identifier:result; 133, identifier:append; 134, subscript; 135, subscript; 136, identifier:value; 137, identifier:key; 138, identifier:value; 139, identifier:key
code: def sort(self, cmp=None, key=None, reverse=False):
          """Sorts rows in the texttable.
  
      Args:
        cmp: func, non default sort algorithm to use.
        key: func, applied to each element before sorting.
        reverse: bool, reverse order of sort.
      """
  
          def _DefaultKey(value):
              """Default key func is to create a list of all fields."""
              result = []
              for key in self.header:
                  # Try sorting as numerical value if possible.
                  try:
                      result.append(float(value[key]))
                  except ValueError:
                      result.append(value[key])
              return result
  
          key = key or _DefaultKey
          # Exclude header by copying table.
          new_table = self._table[1:]
  
          if cmp is not None:
              key = cmp_to_key(cmp)
  
          new_table.sort(key=key, reverse=reverse)
  
          # Regenerate the table with original header
          self._table = [self.header]
          self._table.extend(new_table)
          # Re-write the 'row' attribute of each row
          for index, row in enumerate(self._table):
              row.row = index