[Tutor] Why include "*args" in a function's parameter list when no args are ever passed in?

boB Stepp robertvstepp at gmail.com
Wed Sep 2 23:18:51 EDT 2020


I am reading an interesting Tcl/Tk tutorial at tkdocs.com/tutorial .  In
it the author shows how each GUI example would be implemented in several
languages (Tcl, Ruby, Perl, Python).

So far I have noticed a commonality to all of his Python code involving
callback functions.  Following is a typical example from his "Listbox"
section of https://tkdocs.com/tutorial/morewidgets.html :

# Called when the selection in the listbox changes; figure out
# which country is currently selected, and then lookup its country
# code, and from that, its population.  Update the status message
# with the new population.  As well, clear the message about the
# gift being sent, so it doesn't stick around after we start doing
# other things.
def showPopulation(*args):
     idxs = lbox.curselection()
     if len(idxs)==1:
         idx = int(idxs[0])
         code = countrycodes[idx]
         name = countrynames[idx]
         popn = populations[code]
         statusmsg.set("The population of %s (%s) is %d" % (name, code, popn))
     sentmsg.set('')

I don't understand why he just doesn't leave the parameters area in the
function definition blank instead of inserting "*args" which never gets
used.  Why would one do this?

-- 
Wishing you only the best,

boB Stepp


More information about the Tutor mailing list