From dc7f79af0f7f0c1f358df21b9d0844d300449a17 Mon Sep 17 00:00:00 2001 From: Sampad Kumar Saha Date: Wed, 1 Mar 2017 15:53:21 +0530 Subject: [PATCH 1/8] Modern string formatting in csp.py. --- csp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/csp.py b/csp.py index f300cb816..207576928 100644 --- a/csp.py +++ b/csp.py @@ -344,7 +344,7 @@ def __init__(self, value): self.value = value def __getitem__(self, key): return self.value - def __repr__(self): return '{Any: %r}' % self.value + def __repr__(self): return '{{Any: {0!r}}}'.format(self.value) def different_values_constraint(A, a, B, b): From a6aad1a362af950a93d251634ea625878c8c3c7e Mon Sep 17 00:00:00 2001 From: Sampad Kumar Saha Date: Wed, 1 Mar 2017 16:25:13 +0530 Subject: [PATCH 2/8] Modern string formatting in games.py. --- games.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/games.py b/games.py index 90604bf69..9b98c5638 100644 --- a/games.py +++ b/games.py @@ -203,7 +203,7 @@ def display(self, state): print(state) def __repr__(self): - return '<%s>' % self.__class__.__name__ + return '<{}>'.format(self.__class__.__name__) class Fig52Game(Game): From c22dca0fb21c272173f3f576a83d8547da0bb278 Mon Sep 17 00:00:00 2001 From: Sampad Kumar Saha Date: Wed, 1 Mar 2017 19:34:33 +0530 Subject: [PATCH 3/8] Modern string formatting in learning.py. --- learning.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/learning.py b/learning.py index 0894b2190..ddeed4459 100644 --- a/learning.py +++ b/learning.py @@ -139,8 +139,8 @@ def check_example(self, example): if self.values: for a in self.attrs: if example[a] not in self.values[a]: - raise ValueError('Bad value %s for attribute %s in %s' % - (example[a], self.attrnames[a], example)) + raise ValueError('Bad value {} for attribute {} in {}' + .format(example[a], self.attrnames[a], example)) def attrnum(self, attr): "Returns the number used for attr, which can be a name, or -n .. n-1." @@ -157,7 +157,7 @@ def sanitize(self, example): for i, attr_i in enumerate(example)] def __repr__(self): - return '' % ( + return ''.format( self.name, len(self.examples), len(self.attrs)) # ______________________________________________________________________________ @@ -317,8 +317,8 @@ def display(self, indent=0): subtree.display(indent + 1) def __repr__(self): - return ('DecisionFork(%r, %r, %r)' - % (self.attr, self.attrname, self.branches)) + return ('DecisionFork({}, {}, {})' + .format(self.attr, self.attrname, self.branches)) class DecisionLeaf: @@ -772,9 +772,9 @@ def test(predict, dataset, examples=None, verbose=0): if output == desired: right += 1 if verbose >= 2: - print(' OK: got %s for %s' % (desired, example)) + print(' OK: got {} for {}'.format(desired, example)) elif verbose: - print('WRONG: got %s, expected %s for %s' % ( + print('WRONG: got {}, expected {} for {}'.format( output, desired, example)) return 1 - (right / len(examples)) From 9610929a6a3d2b6bbae9d98efdcdb498fc436106 Mon Sep 17 00:00:00 2001 From: Sampad Kumar Saha Date: Wed, 1 Mar 2017 20:05:16 +0530 Subject: [PATCH 4/8] Modern string formatting in nlp.py. --- nlp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nlp.py b/nlp.py index 7273b98da..9319d2232 100644 --- a/nlp.py +++ b/nlp.py @@ -52,7 +52,7 @@ def isa(self, word, cat): return cat in self.categories[word] def __repr__(self): - return '' % self.name + return ''.format(self.name) E0 = Grammar('E0', Rules( # Grammar for E_0 [Figure 22.4] @@ -158,7 +158,7 @@ def add_edge(self, edge): if edge not in self.chart[end]: self.chart[end].append(edge) if self.trace: - print('Chart: added %s' % (edge,)) + print('Chart: added {}'.format(edge)) if not expects: self.extender(edge) else: From 49039c8cac582c4e9629bec2da21ac57719f6e77 Mon Sep 17 00:00:00 2001 From: Sampad Kumar Saha Date: Wed, 1 Mar 2017 20:11:37 +0530 Subject: [PATCH 5/8] Modern string formatting in probability.py. --- probability.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/probability.py b/probability.py index ed3aa5243..0c7faaed1 100644 --- a/probability.py +++ b/probability.py @@ -80,7 +80,7 @@ def show_approx(self, numfmt='%.3g'): for (v, p) in sorted(self.prob.items())]) def __repr__(self): - return "P(%s)" % self.varname + return "P({0!r})".format(self.varname) class JointProbDist(ProbDist): @@ -117,7 +117,7 @@ def values(self, var): return self.vals[var] def __repr__(self): - return "P(%s)" % self.variables + return "P({0!r})".format(self.variables) def event_values(event, variables): @@ -192,14 +192,14 @@ def variable_node(self, var): for n in self.nodes: if n.variable == var: return n - raise Exception("No such variable: %s" % var) + raise Exception("No such variable: {}".format(var)) def variable_values(self, var): "Return the domain of var." return [True, False] def __repr__(self): - return 'BayesNet(%r)' % self.nodes + return 'BayesNet({0!r})'.format(self.nodes) class BayesNode: From 911f5c651c03c78351ff3156d6c248df652bbfa6 Mon Sep 17 00:00:00 2001 From: Sampad Kumar Saha Date: Wed, 1 Mar 2017 20:16:06 +0530 Subject: [PATCH 6/8] Modern string formatting in search.py. --- search.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/search.py b/search.py index 12a723662..3f3506a8d 100644 --- a/search.py +++ b/search.py @@ -96,7 +96,7 @@ def __init__(self, state, parent=None, action=None, path_cost=0): self.depth = parent.depth + 1 def __repr__(self): - return "" % (self.state,) + return "".format(self.state) def __lt__(self, node): return self.state < node.state @@ -1132,7 +1132,7 @@ def __getattr__(self, attr): return getattr(self.problem, attr) def __repr__(self): - return '<%4d/%4d/%4d/%s>' % (self.succs, self.goal_tests, + return '<{:4d}/{:4d}/{:4d}/{}>'.format(self.succs, self.goal_tests, self.states, str(self.found)[:4]) From 6977180e69a3e0147e72a9257483ef2498c95094 Mon Sep 17 00:00:00 2001 From: Sampad Kumar Saha Date: Thu, 2 Mar 2017 19:09:27 +0530 Subject: [PATCH 7/8] Replaced {0\!r} by {} if %s. --- learning.py | 2 +- nlp.py | 2 +- probability.py | 4 ++-- search.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/learning.py b/learning.py index ddeed4459..63c217a59 100644 --- a/learning.py +++ b/learning.py @@ -317,7 +317,7 @@ def display(self, indent=0): subtree.display(indent + 1) def __repr__(self): - return ('DecisionFork({}, {}, {})' + return ('DecisionFork({0!r}, {0!r}, {0!r})' .format(self.attr, self.attrname, self.branches)) diff --git a/nlp.py b/nlp.py index 9319d2232..e10c3c044 100644 --- a/nlp.py +++ b/nlp.py @@ -52,7 +52,7 @@ def isa(self, word, cat): return cat in self.categories[word] def __repr__(self): - return ''.format(self.name) + return ''.format(self.name) E0 = Grammar('E0', Rules( # Grammar for E_0 [Figure 22.4] diff --git a/probability.py b/probability.py index 0c7faaed1..c0201595f 100644 --- a/probability.py +++ b/probability.py @@ -80,7 +80,7 @@ def show_approx(self, numfmt='%.3g'): for (v, p) in sorted(self.prob.items())]) def __repr__(self): - return "P({0!r})".format(self.varname) + return "P({})".format(self.varname) class JointProbDist(ProbDist): @@ -117,7 +117,7 @@ def values(self, var): return self.vals[var] def __repr__(self): - return "P({0!r})".format(self.variables) + return "P({})".format(self.variables) def event_values(event, variables): diff --git a/search.py b/search.py index 3f3506a8d..fb4e523c0 100644 --- a/search.py +++ b/search.py @@ -96,7 +96,7 @@ def __init__(self, state, parent=None, action=None, path_cost=0): self.depth = parent.depth + 1 def __repr__(self): - return "".format(self.state) + return "".format(self.state) def __lt__(self, node): return self.state < node.state From b9b5ca9d98b5465679666901e3501d1afc5e14a3 Mon Sep 17 00:00:00 2001 From: Sampad Kumar Saha Date: Fri, 3 Mar 2017 17:54:07 +0530 Subject: [PATCH 8/8] Corrected a typo. --- learning.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/learning.py b/learning.py index 63c217a59..41dd324e5 100644 --- a/learning.py +++ b/learning.py @@ -317,7 +317,7 @@ def display(self, indent=0): subtree.display(indent + 1) def __repr__(self): - return ('DecisionFork({0!r}, {0!r}, {0!r})' + return ('DecisionFork({0!r}, {1!r}, {2!r})' .format(self.attr, self.attrname, self.branches))