For the non-programmers among you, please ignore this post as it is written in Geek. Wow … lambda functions are powerful… Take a look at this:
class foo:
__init__():
self.blea = file.open(“somefile”)
read(self):
return self.blea.read()
close(self):
self.blea.close()
With this code calling close, then read returns an error… However if I add :
close(self):
self.blea.close()
self.read = lambda placeholder: “”
Calling read after close now returns an empty string as the read function has been redefined to be an empty lambda function. This little trick has saved me about 30 try/except blocks in my current project.
For those of you that do not program, you may now continue reading…
February 19th, 2005 at 1:59 pm
nerd.
February 19th, 2005 at 7:45 pm
Well, better than trying to capture exceptions… in my case:
error in line (256): corresponding subroutine to event cary.girlfriend(bad.mood) not found! Initiating evasive action .