Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Changes for python3 string formating #471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions probability.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down