Python Forum
function with 'self' input parameter errors out with and without 'self' called
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function with 'self' input parameter errors out with and without 'self' called
#8
"self" is used to accept the instance argument in an instance method call just as "cls" is used to accept the class argument for a class method. The words "self" and "cls" are conventions and the arguments could be named anything, but it is best to follow conventions.

In Python you call an instance method like this "instance.method(args)" where "instance" is an instance of a class, "method" the name of the instance method, and args are whatever additional arguments are passed. Python converts this to "class.method(instance, args)" prepending the instance as the first argument to the method call. The instance argument becomes "self" inside the body of the method.

I think "update_main_tasks()" is a function, not a method and it should not have a "self" argument. When you bind this function to a tkinter widget, the function gets called with an argument, probably a tuple containing information about the event that caused the function to be called. You should find out what this information is. If you don't need the information you should modify the binding to not pass the argument. This is easily done using a lambda expression.
button = tk.Button(root, command=lambda event:update_main_tasks())
Reply


Messages In This Thread
RE: function with 'self' input parameter errors out with and without 'self' called - by deanhystad - Jan-15-2022, 01:26 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  difference between forms of input a list to function akbarza 6 1,157 Feb-21-2024, 08:02 PM
Last Post: bterwijn
  Multiple variable inputs when only one is called for ChrisDall 2 534 Oct-20-2023, 07:43 PM
Last Post: deanhystad
  determine parameter type in definition function akbarza 1 630 Aug-24-2023, 01:46 PM
Last Post: deanhystad
  Function parameter not writing to variable Karp 5 1,031 Aug-07-2023, 05:58 PM
Last Post: Karp
  Couldn't install a go-game called dlgo Nomamesse 14 3,265 Jan-05-2023, 06:38 PM
Last Post: Nomamesse
  [ERROR] ParamValidationError: Parameter validation failed: Invalid type for parameter gdbengo 3 11,395 Dec-26-2022, 08:48 AM
Last Post: ibreeden
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,164 Dec-25-2022, 03:00 PM
Last Post: askfriends
  how can a function find the name by which it is called? Skaperen 18 3,595 Aug-24-2022, 04:52 PM
Last Post: Skaperen
  Showing an empty chart, then input data via function kgall89 0 1,004 Jun-02-2022, 01:53 AM
Last Post: kgall89
  input function question barryjo 12 2,877 Jan-18-2022, 12:11 AM
Last Post: barryjo

Forum Jump:

User Panel Messages

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