Skip to content

Commit 1c181dc

Browse files
Chipe1norvig
authored andcommitted
Changes for python3 string formating (aimacode#471)
* change string format * Fixed string format
1 parent cf743b6 commit 1c181dc

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

probability.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ def normalize(self):
7272
self.prob[val] /= total
7373
return self
7474

75-
def show_approx(self, numfmt='%.3g'):
75+
def show_approx(self, numfmt='{:.3g}'):
7676
"""Show the probabilities rounded and sorted by key, for the
7777
sake of portable doctests."""
78-
return ', '.join([('%s: ' + numfmt) % (v, p)
78+
return ', '.join([('{}: ' + numfmt).format(v, p)
7979
for (v, p) in sorted(self.prob.items())])
8080

8181
def __repr__(self):

utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,10 @@ def issequence(x):
307307
return isinstance(x, collections.abc.Sequence)
308308

309309

310-
def print_table(table, header=None, sep=' ', numfmt='%g'):
310+
def print_table(table, header=None, sep=' ', numfmt='{}'):
311311
"""Print a list of lists as a table, so that columns line up nicely.
312312
header, if specified, will be printed as the first row.
313-
numfmt is the format for all numbers; you might want e.g. '%6.2f'.
313+
numfmt is the format for all numbers; you might want e.g. '{:.2f}'.
314314
(If you want different formats in different columns,
315315
don't use print_table.) sep is the separator between columns."""
316316
justs = ['rjust' if isnumber(x) else 'ljust' for x in table[0]]

0 commit comments

Comments
 (0)