Hi all,<br><br>I'm a novice learner of python and get caught in the following trouble and hope experienced users can help me solve it:)<br><br>Code:<br>-----------------------------------------------------------------------<br>
$ cat Muffle_ZeroDivision.py<br>#!/usr/bin/env python<br><br>class MuffledCalculator:<br> muffled = False<br> def clac(self,expr):<br> try:<br> return eval(expr)<br> except:<br> if self.muffled:<br>
print 'Division by zero is illegal'<br> else:<br> raise<br>--------------------------------------------------------------------------<br><br>$ python<br>Python 2.7 (r27:82500, Sep 16 2010, 18:03:06) <br>
[GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2<br>Type "help", "copyright", "credits" or "license" for more information.<br>>>> import Muffle_ZeroDivision<br>>>> calc = Muffle_ZeroDivision.MuffledCalculator()<br>
>>> calc = ('10/2')<br>>>> calc = Muffle_ZeroDivision.MuffledCalculator()<br>>>> calc('10/2')<br>Traceback (most recent call last):<br> File "<stdin>", line 1, in <module><br>
AttributeError: MuffledCalculator instance has no __call__ method<br><br>----------------------------------------------------------------------------<br><br>There is an AttributeError that this instance doesn't have the __call__ method, so how to add this kind of method to my instance?<br>
<br>Thanks a lot in advance.<br><br>Regards<br>Frank.Cui<br><br>