Steven D. Majewski
sdm7g at virginia.edu
Wed Feb 14 04:32:13 CET 2001
On Wed, 14 Feb 2001, Dan Parisien wrote:
> I want to do this
> 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...
No -- the problem is that 'lambda' expressions take an expression
and 'del' is a statement in the python grammar.
You'll get the same error if you try: 'lambda x: import sys' --
The problem is 'del' , not 'd[p]' .
> 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)?
I think the more pythonic way to do this would be to subclass
UserDict and make a method that deletes the keys.
---| Steven D. Majewski (804-982-0831) <sdm7g at Virginia.EDU> |---
---| Department of Molecular Physiology and Biological Physics |---
---| University of Virginia Health Sciences Center |---
---| P.O. Box 10011 Charlottesville, VA 22906-0011 |---
"All operating systems want to be unix,
All programming languages want to be lisp."
More information about the Python-list