On Sun, 25 May 2008 13:43:15 +0200, Martin Manns wrote: > I try to get a set of lambda functions that allows me executing each > function code exactly once. Therefore, I would like to modify the set > function to compare the func_code properties (or the lambda functions to > use this property for comparison).
With Ivan's approach, you lose access to the actual lambdas, so you need to create a new function and then modify its code object to actually call the code; this seems a little clunky to me. You might instead want to wrap the lambdas in an object that will do the comparison you want: class Code(object): def __init__(self, func): self._func = func def __cmp__(self, other): return cmp(self._func.func_code, other._func.func_code) def __call__(self, *args, **kwargs): return self._func(*args, **kwargs) func_set = set(Code(f) for f in funclist) -- http://mail.python.org/mailman/listinfo/python-list