Python Forum
Confusion about TypeError and 'self'
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Confusion about TypeError and 'self'
#1
Hey everyone, this is my first post so I hope this is clear.
I am working on some code where the user is asked to select from a comboBox.

This problem I have is the code is suggesting I need to include the self argument however when I include it, it still errors out. I've gone around in circles for a couple of days now. Your insights would be greatly appreciated.

WITHOUT SELF ARGUMENT
    def play(self):
        guess = str(self.ui.comboBox.currentText())
        return guess

    if play() == comp_num:
        winmessage()
    else:
        losemessage()
And this is the Error
Error:
Traceback (most recent call last): File "D:/Muzzrooms/Desktop/Year 11/Term 2/Digital Solutions/Guessing Game/Guessing_game_completed.py", line 15, in <module> class MainWindow: File "D:/Muzzrooms/Desktop/Year 11/Term 2/Digital Solutions/Guessing Game/Guessing_game_completed.py", line 43, in MainWindow if play() == comp_num: TypeError: play() missing 1 required positional argument: 'self'
WITH SELF ARGUMENT
    def play(self):
        guess = str(self.ui.comboBox.currentText())
        return guess

    if play(self) == comp_num:
        winmessage()
    else:
        losemessage()
And this is the error I receive if I include the self argument.
Error:
Traceback (most recent call last): File "D:/Muzzrooms/Desktop/Year 11/Term 2/Digital Solutions/Guessing Game/Guessing_game_completed.py", line 15, in <module> class MainWindow: File "D:/Muzzrooms/Desktop/Year 11/Term 2/Digital Solutions/Guessing Game/Guessing_game_completed.py", line 43, in MainWindow if play(self) == comp_num: NameError: name 'self' is not defined
Your help is greatly appreciated;
-Muzzrooms
Reply


Messages In This Thread
Confusion about TypeError and 'self' - by Muzzrooms - Apr-29-2020, 09:48 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020