typeerror 在类 python 中不带参数

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

我定义了 self,我在同步中没有看到任何错误,你们认为错误是什么?

class colormac:
    def __init__(self, color, elmnt=None):
        if isinstance(color, dict):
            self.attachValues(color)
        else:
            self.attachValues(toColorObject(color))
        if elmnt:
            elmnt.style.backgroundColor = self.to_rgb_string()


bockColor= colorcat.colormac("rgb(0, 191, 255)")


TypeError: colormac() takes no arguments
python syntax compiler-errors typeerror
1个回答
0
投票

类的说法是错误的,应该是:

class colormac:
   ...

TypeError
来自类定义语句,而不是来自实例化对象的最后一行。

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