# 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 [EMAIL PROTECTED] # # 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 ()
|
_______________________________________________ users-ironpython.com mailing list users-ironpython.com@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com