code: def dump_counts(self, out=sys.stdout, count_fn=len, colwidth=10):
          if len(self._pivot_attrs) == 1:
              out.write("Pivot: %s\n" % ','.join(self._pivot_attrs))
              maxkeylen = max(len(str(k)) for k in self.keys())
              maxvallen = colwidth
              keytally = {}
              for k, sub in self.items():
                  sub_v = count_fn(sub)
                  maxvallen = max(maxvallen, len(str(sub_v)))
                  keytally[k] = sub_v
              for k, sub in self.items():
                  out.write("%-*.*s " % (maxkeylen, maxkeylen, k))
                  out.write("%*s\n" % (maxvallen, keytally[k]))
          elif len(self._pivot_attrs) == 2:
              out.write("Pivot: %s\n" % ','.join(self._pivot_attrs))
              maxkeylen = max(max(len(str(k)) for k in self.keys()), 5)
              maxvallen = max(max(len(str(k)) for k in self.subtables[0].keys()), colwidth)
              keytally = dict((k, 0) for k in self.subtables[0].keys())
              out.write("%*s " % (maxkeylen, ''))
              out.write(' '.join("%*.*s" % (maxvallen, maxvallen, k) for k in self.subtables[0].keys()))
              out.write(' %*s\n' % (maxvallen, 'Total'))
              for k, sub in self.items():
                  out.write("%-*.*s " % (maxkeylen, maxkeylen, k))
                  for kk, ssub in sub.items():
                      ssub_v = count_fn(ssub)
                      out.write("%*d " % (maxvallen, ssub_v))
                      keytally[kk] += ssub_v
                      maxvallen = max(maxvallen, len(str(ssub_v)))
                  sub_v = count_fn(sub)
                  maxvallen = max(maxvallen, len(str(sub_v)))
                  out.write("%*d\n" % (maxvallen, sub_v))
              out.write('%-*.*s ' % (maxkeylen, maxkeylen, "Total"))
              out.write(' '.join("%*d" % (maxvallen, tally) for k, tally in sorted(keytally.items())))
              out.write(" %*d\n" % (maxvallen, sum(tally for k, tally in keytally.items())))
          else:
              raise ValueError("can only dump summary counts for 1 or 2-attribute pivots")