Closures

Robert Kern rkern at ucsd.edu
Thu Apr 29 19:21:37 EDT 2004


Michael Sparks wrote:

> On Thu, 29 Apr 2004, Gustavo Niemeyer wrote:
> 
> 
>>class Closure:
>>    def __init__(self):
>>        self.__dict__ = sys._getframe().f_back.f_locals
> 
> 
> Out of interest how portable is this? Strikes me as extremely useful
> class to have lying around :) The only thing that makes me wonder is the
> access to _getframe...

Well, Guido considers "anything that uses sys._getframe() to be a danger 
to society unless proven innocent," but what does he know? ;-)

http://article.gmane.org/gmane.comp.python.devel/58837

> Michael

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter



More information about the Python-list mailing list