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): 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): diff --git a/learning.py b/learning.py index 0894b2190..41dd324e5 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({0!r}, {1!r}, {2!r})' + .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)) diff --git a/nlp.py b/nlp.py index 7273b98da..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 '' % 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: diff --git a/probability.py b/probability.py index ed3aa5243..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(%s)" % 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(%s)" % self.variables + return "P({})".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: diff --git a/search.py b/search.py index 12a723662..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 "" % (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]) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy