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

Jeremy Ng

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'
JafetGado

Your function main takes in the argument self, but in your execution, main(), you do not pass in any arguments.

First, self is used in object oriented programming, when you have a class with attributes and methods. 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?

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()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

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

TypeError: Missing 1 required positional argument: 'self'

Rookie coder: main() missing 1 required positional argument: 'self'?

How to Solve this " TypeError: read() missing 1 required positional argument: 'self' "

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

TypeError: save() missing 1 required positional argument: 'self' : DjangoRestframework

TypeError at / save() missing 1 required positional argument: 'self'

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

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

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

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

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

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

Python - TypeError: listen() missing 1 required positional argument: 'self'

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

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

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

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

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

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

Getting TypeError fit() missing 1 required positional argument: 'self'

TypeError at /listing: save() missing 1 required positional argument: 'self'

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

TypeError: GoogleAuth.LocalWebserverAuth() missing 1 required positional argument: 'self'

Missing 1 required positional argument: 'self' missing

save() missing 1 required positional argument 'self'

python: missing 1 required positional argument: 'self'

fit() missing 1 required positional argument: 'self'

missing 1 required positional argument: 'self' in class