On 11/02/2011 05:42, Ben Finney wrote:
Rotwang<[email protected]> 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.
Thanks.
What part is inelegant to your eye?
I guess the fact that it exploits the way Python evaluates default function arguments to achieve something other than what they were intended for. Still, I see that Chris suggested the same solution (thanks, Chris) so it clearly isn't something that's frowned upon.
-- http://mail.python.org/mailman/listinfo/python-list
