TypeError:+ 不支持的操作数类型:'Coverage' 和 'Coverage'

问题描述 投票:0回答:0

我有一个具有 add 属性的 Coverage 类。程序在 PC 上启动后,可以正常运行。一旦我将它部署到 Pythonanywhere 主机上,我就收到了上述错误。

TypeError:+ 不支持的操作数类型:'Coverage' 和 'Coverage'

课程覆盖率

class Coverage:
    def __init__(self, string=''):
        self.string = string

    def __mul__(self, other):
        list_cubes1 = [Coverage(el) for el in self.string.split(' + ')]
        list_cubes2 = [Coverage(el) for el in other.string.split(' + ')]
        res = None
        for el2 in list_cubes2:
            for el1 in list_cubes1:
                to_add = remove_equal(el1.string.split(',') + el2.string.split(','))
                to_add = Coverage(','.join(to_add))
                res = to_add if res is None else res + to_add
        return res

    def __add__(self, other):
        list_cubes1 = [Coverage(el) for el in self.string.split(' + ')]
        list_cubes2 = [Coverage(el) for el in other.string.split(' + ')]

        res = list_cubes1
        for el2 in list_cubes2:
            bad = False
            for j in range(len(res)):
                if el2 in res[j]:
                    res[j] = el2
                    bad = True
                elif res[j] in el2:
                    bad = True
                    break
            if not bad:
                res.append(el2)
        list1 = remove_equal([el.string for el in res])
        return Coverage(' + '.join(list1))

    def __repr__(self):
        return self.string

    def __eq__(self, other):
        return self.string == other.string

    def __contains__(self, item):
        for c in item.string:
            if c not in self.string:
                return False
        return True

    def __hash__(self):
        return hash(self.string)

为什么这会在部署时导致错误?

python pythonanywhere
© www.soinside.com 2019 - 2024. All rights reserved.