instance has no __call__ method

frank cui frankcui24 at gmail.com
Fri Dec 10 05:20:53 EST 2010


Hi all,

I'm a novice learner of python and get caught in the following trouble and
hope experienced users can help me solve it:)

Code:
-----------------------------------------------------------------------
$ cat Muffle_ZeroDivision.py
#!/usr/bin/env python

class MuffledCalculator:
    muffled = False
    def clac(self,expr):
        try:
            return eval(expr)
        except:
            if self.muffled:
                print 'Division by zero is illegal'
            else:
                raise
--------------------------------------------------------------------------

$ python
Python 2.7 (r27:82500, Sep 16 2010, 18:03:06)
[GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Muffle_ZeroDivision
>>> calc = Muffle_ZeroDivision.MuffledCalculator()
>>> calc = ('10/2')
>>> calc = Muffle_ZeroDivision.MuffledCalculator()
>>> calc('10/2')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: MuffledCalculator instance has no __call__ method

----------------------------------------------------------------------------

There is an AttributeError that this instance doesn't have the __call__
method, so how to add this kind of method to my instance?

Thanks a lot in advance.

Regards
Frank.Cui
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101210/acb7f3d8/attachment-0001.html>


More information about the Python-list mailing list