The __round__ special method was introduced only in Python 3. There is no special method support in Python 2.
You will need to use the highlighted method instead of the function:
class Vector(object): def __init__(self, value): self.value = value def round(self, n): return [round(x, n) for x in self.value]
or you will need to provide your own round() function:
import __builtin__ def round(number, digits=0): try: return number.__round__(digits) except AttributeError: return __builtin__.round(number, digits)
You can even defuse this in the __builtins__ namespace:
import __builtin__ _bltin_round = __builtin__.round def round(number, digits=0): try: hook = number.__round__ except AttributeError: return _bltin_round(number, digits) else:
Martijn Pieters Apr 17 '13 at 11:18 2013-04-17 11:18
source share