Function returns a function

James Stroud jstroud at mbi.ucla.edu
Tue Sep 6 22:59:19 CEST 2005


Hello,

I want a "function factory" function in python. To do this I made a class like 
such (this is for Tkinter, in case your wondering):

class FunctionMaker:
  def __init__(self, avar, function, label)
    self.var = avar
    self.function = function
    self.label = label
  def __call__(self, e=None):
    self.avar.set(self.label)
    self.function()

It seems that it would make more sense to make this a function and add it to 
the mixin I am writing. But I'm not quite sure how to do this without making 
lambdas, which seem a little messy and also look to be on the brink of 
deprecation (really not trying to start a lambda pro/con thread here).

Any ideas on how to do this with a regular function, or is the way I've done 
it the pythonic choice?

James

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/



More information about the Python-list mailing list