AttributeError: 'super' object has no attribute '_init_'报错如何解决
时间: 2024-05-22 12:09:27 浏览: 41
这个错误通常是因为在使用super()函数时,出现了拼写错误,导致Python无法找到正确的属性。您可以检查一下您代码中对super()的使用是否有误,确保拼写正确,并且确保您正在调用正确的父类方法。此外,还可能是由于您没有正确地初始化父类的__init__方法,导致出现此错误。请检查您的代码以确保您正确地初始化了父类。
另外,如果您能提供更多上下文或代码示例,我可以更准确地为您解决这个问题。
相关问题
AttributeError: 'super' object has no attribute '_Net__init'
AttributeError: 'super' object has no attribute '_Net__init'是一个Python错误,通常是由于在子类中未正确调用父类的构造函数而导致的。在这种情况下,子类中的__init__方法可能会覆盖父类中的__init__方法,从而导致错误。要解决这个问题,可以在子类的__init__方法中调用父类的__init__方法,以确保正确地初始化父类的属性。例如,可以使用以下代码来调用父类的__init__方法:
```
class ChildClass(ParentClass):
def __init__(self, arg1, arg2):
super().__init__(arg1)
self.arg2 = arg2
```
这将调用父类的__init__方法,并将arg1传递给它,然后在子类中设置arg2属性。这样可以确保正确地初始化父类的属性,并避免出现AttributeError: 'super' object has no attribute '_Net__init'这样的错误。
AttributeError: 'super' object has no attribute '_Generator__init'
AttributeError: 'super' object has no attribute '_Generator__init'是一个Python错误,通常在使用super()函数时出现。这个错误的原因是在使用super()函数时,它无法找到父类的__init__()方法。这可能是由于子类中的__init__()方法覆盖了父类的__init__()方法,或者是由于子类没有正确地调用父类的__init__()方法。要解决这个错误,可以检查子类的__init__()方法是否正确地调用了父类的__init__()方法,或者尝试在子类中显式地调用父类的__init__()方法。
1. 什么是super()函数?
2. Python中的继承机制是什么?
3. 如何避免AttributeError: 'super' object has no attribute '_Generator__init'错误?
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)