crazy lambdas

Dan Parisien dan at eevolved.com
Tue Feb 13 21:32:48 EST 2001


I want to do this

class Event:
        def __init__(self):
                self.callbacks = []

        def trigger(self):
                for i in self.callbacks:
                        i()

e = Event()

person = "me"
dict = {person:1}

e.callbacks.append(lambda d=dict, p=person: del d[p])

# .... later

e.trigger() #deletes
---
those who use lambdas alot will notice my mistake. I, however, do not know 
what I am doing wrong. I think it has something to do with the fact 'del 
d[p]' doesn't have a value...

Is it possible to do what I want (make a custom one-time-use function that 
is called much later and deletes a key from a dictionary)?

thanks,
Dan



More information about the Python-list mailing list