4 ms·
Total nitpick, but it annoys me when people implement something in Python but use ancient syntax. return '<M a: %s>' % self.a Should be: return '<M a: {}
by bkeroack 12y ago
Total nitpick, but it annoys me when people implement something in Python but use ancient syntax.
return '<M a: %s>' % self.a
Should be:
return '<M a: {}>'.format(self.a)
And:
class M(object):
Should be:
class M:
etc.
- jonhohle 12y agoI can see why you might want the second change (discarding superfluous information), but string formatting looks better to me in the first case: it's more terse, and embeds type information in the format string using a well known and understood convention. Why do you prefer the explicit method call over an operator?
- physPop 12y ago% format is deprecated in the python spec.
- bkeroack 12y agoIt's arguable, but operator overloading should only be used (if at all) when there is conceptual symmetry between the standard and overloaded usage (eg, adding two datetime objects with '+'). I can't think of any way that taking the modulo of two strings logically results in interpolation. If anything, it should do something like return the original string with all instances of the argument removed. It's just simpler to not support it at all and use the standard .format() method. There's also the fact that it's deprecated, of course. :)
- illicium 12y agoclass M(object): is a new-style class in Python 2.x, in which it's the correct syntax: https://docs.python.org/2/glossary.html#term-new-style-class https://docs.python.org/2/glossary.html#term-new-style-class It's different in Python 3 but that doesn't matter because Python 3 is largely irrelevant.