添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

TypeError: super(type, obj): obj must be an instance or subtype of type

74浏览 · 2024-03-08 15:51:34
这个错误通常表示您在使用 `super()` [函数](https://geek.csdn.net/educolumn/ba94496e6cfa8630df5d047358ad9719?dp_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NDQ0MDg2MiwiZXhwIjoxNzA3MzcxOTM4LCJpYXQiOjE3MDY3NjcxMzgsInVzZXJuYW1lIjoid2VpeGluXzY4NjQ1NjQ1In0.RrTYEnMNYPC7AQdoij4SBb0kKEgHoyvF-bZOG2eGQvc&spm=1055.2569.3001.10083)时,传递了一个不正确的参数。`super()` [函数](https://geek.csdn.net/educolumn/ba94496e6cfa8630df5d047358ad9719?dp_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NDQ0MDg2MiwiZXhwIjoxNzA3MzcxOTM4LCJpYXQiOjE3MDY3NjcxMzgsInVzZXJuYW1lIjoid2VpeGluXzY4NjQ1NjQ1In0.RrTYEnMNYPC7AQdoij4SBb0kKEgHoyvF-bZOG2eGQvc&spm=1055.2569.3001.10083)用于在子类中调用父类的方法。请确保您已正确地传递了子类和实例[对象](https://geek.csdn.net/educolumn/04c51611e4b730957464192e0307b82c?spm=1055.2569.3001.10083)作为参数,如下所示: ```python class MyClass(MyParentClass): def __init__(self, arg1, arg2): super().__init__(arg1) 在上面的示例中,`MyClass` 是子类,`MyParentClass` 是父类。在 `MyClass` 的构造[函数](https://geek.csdn.net/educolumn/ba94496e6cfa8630df5d047358ad9719?dp_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NDQ0MDg2MiwiZXhwIjoxNzA3MzcxOTM4LCJpYXQiOjE3MDY3NjcxMzgsInVzZXJuYW1lIjoid2VpeGluXzY4NjQ1NjQ1In0.RrTYEnMNYPC7AQdoij4SBb0kKEgHoyvF-bZOG2eGQvc&spm=1055.2569.3001.10083)中,我们调用了 `MyParentClass` 的构造[函数](https://geek.csdn.net/educolumn/ba94496e6cfa8630df5d047358ad9719?dp_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NDQ0MDg2MiwiZXhwIjoxNzA3MzcxOTM4LCJpYXQiOjE3MDY3NjcxMzgsInVzZXJuYW1lIjoid2VpeGluXzY4NjQ1NjQ1In0.RrTYEnMNYPC7AQdoij4SBb0kKEgHoyvF-bZOG2eGQvc&spm=1055.2569.3001.10083),以便在实例化 `MyClass` 时初始化父类的属性。如果您仍然遇到问题,请提供更多上下文或代码片段,以便我能够更好地帮助您。
相关问题
这个错误是因为你传递了一个列表类型的参数给一个要求传递浮点数类型参数的函数。你需要检查代码中涉及到这个函数的地方,看看传递参数的类型是否正确。 如果你需要将一个列表类型的参数转换成浮点数类型,可以使用以下代码: ```python eps_list = [1.0, 2.0, 3.0] eps_float = float(eps_list[0]) 这里将列表中的第一个元素转换为浮点数类型,你可以根据需要选择转换列表中的其他元素。
This error occurs when the variable passed as the `norm` argument to a matplotlib function is not an instance of `matplotlib.colors.Normalize` or `None`. To fix this error, make sure that the variable you are passing as `norm` is an instance of `matplotlib.colors.Normalize` or `None`. If it is not, you can create an instance of `Normalize` using the `matplotlib.colors.Normalize` class or set `norm=None` to use the default normalization. For example: import matplotlib.pyplot as plt import matplotlib.colors as mcolors norm = mcolors.Normalize(vmin=0, vmax=1) plt.scatter(x, y, c=z, cmap='viridis', norm=norm)