Parameterized functions of no arguments?

Ben Finney ben+python at benfinney.id.au
Fri Feb 11 00:42:32 EST 2011


Rotwang <sg552 at hotmail.co.uk> writes:

> Here's something that does work:
>
>     menu = Tkinter.Menu(master, tearoff = 0)
>     for k in x:
>         def f(j = k):
>             [do something that depends on j]
>         menu.add_command(label = str(k), command = f)
>
> Still, I'd like to know if there's a more elegant method for creating
> a set of functions indexed by an arbitrary list.

That already seems quite elegant to me. What part is inelegant to your
eye?

-- 
 \         “I'm not a bad guy! I work hard, and I love my kids. So why |
  `\      should I spend half my Sunday hearing about how I'm going to |
_o__)                                            Hell?” —Homer Simpson |
Ben Finney



More information about the Python-list mailing list