不明白这个“对象不可调用”

2024-09-28 10:13:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在设置单元测试,当试图调用函数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)

我希望代码能正常工作,但我无法绕过错误。在


Tags: thetoselfcoordinateobjectdef错误单元测试

热门问题