-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Modern String Formatting in Code #292
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
Changes from 6 commits
dc7f79a
a6aad1a
c22dca0
9610929
49039c8
911f5c6
6977180
b9b5ca9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,7 @@ def isa(self, word, cat): | |
return cat in self.categories[word] | ||
|
||
def __repr__(self): | ||
return '<Grammar %s>' % self.name | ||
return '<Grammar {0!r}>'.format(self.name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please elaborate on why are using {0!r} instead of {} given self.name is not a special object for which we have defined repr There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. |
||
|
||
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: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can stick with {} here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. |
||
|
||
|
||
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: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not right. You are using the repr of self.attr thrice here.