简体   繁体   English

TypeError: main() missing 1 required positional argument: 'self'

[英]TypeError: main() missing 1 required positional argument: 'self'

My code and error is below and I was trying to understand why I am getting the error and how to fix it.我的代码和错误在下面,我试图理解为什么我会收到错误以及如何修复它。 I tried this without self and got another error我在没有自我的情况下尝试了这个并得到了另一个错误

TypeError: load_data() takes 0 positional arguments but 1 was given. 
def main(self):

    training_loader, validation_loader, testing_loader = Utilities3.load_data(data)
    model, optimizer, criterion = Utilities3.network_construct(structure, drop, hidden_layer, learningrate, device)
    Utilities3.do_deep_learning(model, optimizer, criterion, epochs, 40, training_loader, device)
    Utilities3.save_checkpoint(model, path, structure, hidden_layer, drop, learningrate)
    print("Training is finish")


if __name__== "__main__":
    main()
TypeError                                 Traceback (most recent call last)
<ipython-input-25-77e46aea71ac> in <module>()
     49 
     50 if __name__== "__main__":
---> 51     main()

TypeError: main() missing 1 required positional argument: 'self'

Your function main takes in the argument self , but in your execution, main() , you do not pass in any arguments.您的函数main接受参数self ,但在您的执行中, main() ,您不传入任何参数。

First, self is used in object oriented programming, when you have a class with attributes and methods.首先,当你有一个带有属性和方法的类时, self用于面向对象的编程。 But that is not what you have here.但这不是你在这里所拥有的。 Moreover, you don't seem to be using self at all in the function, so why do you have it as an argument?此外,您似乎根本没有在函数中使用self ,那么为什么要将它作为参数呢?

Do this instead:改为这样做:


def main():

    training_loader, validation_loader, testing_loader = Utilities3.load_data(data)
    model, optimizer, criterion = Utilities3.network_construct(structure, drop, hidden_layer, learningrate, device)
    Utilities3.do_deep_learning(model, optimizer, criterion, epochs, 40, training_loader, device)
    Utilities3.save_checkpoint(model, path, structure, hidden_layer, drop, learningrate)
    print("Training is finish")


if __name__== "__main__":
    main()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型错误:exe() 缺少 1 个必需的位置参数:&#39;self&#39; - TypeError: exe() missing 1 required positional argument: 'self' TypeError:str()缺少1个必需的位置参数:&#39;self&#39; - TypeError: str() missing 1 required positional argument: 'self' TypeError:toString()缺少1个必需的位置参数:&#39;self&#39; - TypeError: toString() Missing 1 required positional argument: 'self' 捕获 TypeError:缺少 1 个必需的位置参数:'self' - Catching TypeError: Missing 1 required positional argument: 'self' TypeError:endturn()缺少1个必需的位置参数:&#39;self&#39; - TypeError: endturn() missing 1 required positional argument: 'self' 类型错误:kollision() 缺少 1 个必需的位置参数:&#39;self&#39; - TypeError : kollision() missing 1 required positional argument: 'self' TypeError:itertuples()缺少1个必需的位置参数:“ self” - TypeError: itertuples() missing 1 required positional argument: 'self' 类型错误:get() 缺少 1 个必需的位置参数:“self” - TypeError: get() missing 1 required positional argument: 'self' 类型错误:mainloop() 缺少 1 个必需的位置参数:'self' - TypeError: mainloop() missing 1 required positional argument: 'self' 类型错误:close() 缺少 1 个必需的位置参数:'self' - TypeError: close() missing 1 required positional argument: 'self'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM