Defining "add" function in a class
<p>I'm writing my own code language in Python (called Bean), and I want the math functions to have the syntax:</p>

<p>print math.add(3+7)<br>
==>10</p>

<p>print math.mul(4*8)<br>
==>32</p>

<p>and so on. So far my code is:</p>

<pre><code>bean_version = "1.0"
console = []
print "Running Bean v%s" % bean_version
#Math Function
class math(object):
    def __init__(self, add, sub, mul, div):
        self.add = add
        self.sub = sub
        self.mul = mul
        self.div = div
    def add(self):
        print self.add
math = math(1,0,0,0)
print math.add()
</code></pre>

<p>But this will return an error, saying that <em>TypeError: 'int' object is not callable</em>. I can change the "add" function to a different name and it will work, but I would like to use "add" as the name.<br>
Thanks (This is Python 2.7.10 by the way)</p>

<p>If you don't want to change the name of the add function, you can just change <code>self.add</code>. These two <code>add</code>s are conflicting with each other. You will not get any error if you run this:</p>

<pre><code>bean_version = "1.0"
console = []
print "Running Bean v%s" % bean_version
#Math Function
class math(object):
    def __init__(self, add, sub, mul, div):
        self.adds = add
        self.sub = sub
        self.mul = mul
        self.div = div
    def add(self):
        print self.adds
math = math(1,0,0,0)
print math.add()
</code></pre>

python python-2.7