我正在设置单元测试,当尝试调用函数 Pt2D
时,我收到错误 TypeError: 'Pt2D' object is not callable
。
在搜索问题时,我已经尝试了前几页上的所有其他解决方案。这两个程序位于不同的文件中,我正在导入第一个类。
class Pt2D(object):
"""Straightforward 2D point class.
Args:
x (float, optional): The initial x-coordinate. Defaults to 0.
y (float, optional): The initial y-coordinate. Defaults to 0.
"""
def __init__(self, x=0, y=0):
class TestPt2D(TestCase):
def setUp(self):
self.geo = Pt2D()
def tearDown(self):
pass
def test_stuff(self):
y1value = self.geo(0)
y2value = self.geo(1)
ymidvalue = self.geo(0.5)
我希望代码能够正常工作,但我无法解决该错误。
最佳答案
填充您的__init__
方法:
def __init__(self, x=0, y=0):
self.x = x
self.y = y
关于python - 不明白这个 "object not callable"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56677189/