[IronPython] self not known in lambda function

J. de Hooge info at geatec.com
Fri Sep 2 16:18:03 CEST 2005


# Hi,

#

# Might this be a small bug in IronPython? 'self' is not known inside the
definition of a lambda function

# I tried to insulate the problem in a small (admittedly pointless) program,
not to bother you with bulky app. code

# I am using IronPython 0.9.1

#

# Kind regards

# Jacques de Hooge   info at geatec.com

#

# This example will print the following:

# ======================================

#

# workaround

# Traceback (most recent call last):

#   at __main__.Initialize() in C:\activ_dell\prog\fun\src\funDebug.py:line
29

#   at __main__.lamda$1$f5()

# NameError: name 'self' not defined

#

# ======================================

 

class WorkAround:

       def __init__ (self):

              global this

              this = self

              self.setPrintWithoutParams (lambda: this.printWithParams
('workaround'))

              

       def printWithParams (self, text):

              print text

              

       def setPrintWithoutParams (self, printWithoutParams):

              self.printWithoutParams = printWithoutParams 

 

workAround  = WorkAround ()

workAround.printWithoutParams ()

 

 

 

class Problem:

       def __init__ (self):

              self.setPrintWithoutParams (lambda: self.printWithParams
('problem'))

              

       def printWithParams (self, text):

              print text

              

       def setPrintWithoutParams (self, printWithoutParams):

              self.printWithoutParams = printWithoutParams 

 

problem  = Problem ()

problem.printWithoutParams ()

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20050902/7757ed76/attachment.html>


More information about the Ironpython-users mailing list