diff --git a/probability.py b/probability.py index e102e4dd8..347efc7bd 100644 --- a/probability.py +++ b/probability.py @@ -72,10 +72,10 @@ def normalize(self): self.prob[val] /= total return self - def show_approx(self, numfmt='%.3g'): + def show_approx(self, numfmt='{:.3g}'): """Show the probabilities rounded and sorted by key, for the sake of portable doctests.""" - return ', '.join([('%s: ' + numfmt) % (v, p) + return ', '.join([('{}: ' + numfmt).format(v, p) for (v, p) in sorted(self.prob.items())]) def __repr__(self): diff --git a/utils.py b/utils.py index ed44f1e9e..43aaeec04 100644 --- a/utils.py +++ b/utils.py @@ -307,10 +307,10 @@ def issequence(x): return isinstance(x, collections.abc.Sequence) -def print_table(table, header=None, sep=' ', numfmt='%g'): +def print_table(table, header=None, sep=' ', numfmt='{}'): """Print a list of lists as a table, so that columns line up nicely. header, if specified, will be printed as the first row. - numfmt is the format for all numbers; you might want e.g. '%6.2f'. + numfmt is the format for all numbers; you might want e.g. '{:.2f}'. (If you want different formats in different columns, don't use print_table.) sep is the separator between columns.""" justs = ['rjust' if isnumber(x) else 'ljust' for x in table[0]]