我是 Python 对象的新手,有很多问题。我需要将一个函数传递给我的对象,然后评估该函数。代码与此类似:
from sympy import var
class eval:
def __init__(self, M):
self.M = M
def fun(self, x):
M = self.M
print M(x)
x = var('x')
ak = eval(x+2)
ak.fun(x)
这是错误:
TypeError
Traceback (most recent call last)
(ipython-input-1-b7ef311bd1f0> in <module)()
12
13 ak = eval(x+2)
---> 14 ak.fun(x)
(ipython-input-1-b7ef311bd1f0) in fun(self, x)
7 def fun(self, x):
8 M = self.M
----> 9 print M(x)
10
11 x = var('x')
TypeError: 'Add' object is not callable