From c318fafb71171cf48640e7744feb26811da65f26 Mon Sep 17 00:00:00 2001 From: Chipe1 Date: Sun, 2 Apr 2017 09:11:49 +0530 Subject: [PATCH 1/2] change string format --- probability.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/probability.py b/probability.py index e102e4dd8..1c5ba62c2 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([('{0}: {1:.' + numfmt + '}').format(v, p) for (v, p) in sorted(self.prob.items())]) def __repr__(self): From 51261325fcdb27122b0c8f55ae45d385e030fe51 Mon Sep 17 00:00:00 2001 From: Chipe1 Date: Sun, 2 Apr 2017 09:29:25 +0530 Subject: [PATCH 2/2] Fixed string format --- probability.py | 4 ++-- utils.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/probability.py b/probability.py index 1c5ba62c2..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([('{0}: {1:.' + numfmt + '}').format(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]]