Getting a set of lambda functions

2008-05-25 Thread Martin Manns
Hi, 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). (The reason is that the real function list

Re: Getting a set of lambda functions

2008-05-25 Thread Ivan Illarionov
On Sun, 25 May 2008 13:43:15 +0200, Martin Manns wrote: Hi, 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

Re: Getting a set of lambda functions

2008-05-25 Thread Ivan Illarionov
On Sun, 25 May 2008 13:43:15 +0200, Martin Manns wrote: Hi, 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

Re: Getting a set of lambda functions

2008-05-25 Thread Martin Manns
On Sun, 25 May 2008 12:14:25 + (UTC) Ivan Illarionov [EMAIL PROTECTED] wrote: On Sun, 25 May 2008 13:43:15 +0200, Martin Manns wrote: Maybe make a set of code objects? func_code_set = set([f.func_code for f in funclist]) funclist = [] for fc in func_code_set: f = lambda x: x

Re: Getting a set of lambda functions

2008-05-25 Thread I V
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

Re: Getting a set of lambda functions

2008-05-25 Thread bearophileHUGS
I V: You might instead want to wrap the lambdas in an object that will do the comparison you want: This looks very nice, I haven't tried it yet, but if it works well then it may deserve to be stored in the cookbook, or better, it may become the built-in behavior of hashing functions. Bye,

Re: Getting a set of lambda functions

2008-05-25 Thread bearophileHUGS
This may have some bugs left, but it looks a bit better: from inspect import getargspec class HashableFunction(object): Class that can be used to wrap functions, to allow their hashing, for example to create a set of unique functions. func_strings = ['x', 'x+1', 'x+2', 'x']

Re: Getting a set of lambda functions

2008-05-25 Thread Denis Kasak
On Sun, May 25, 2008 at 1:43 PM, Martin Manns [EMAIL PROTECTED] wrote: Hi, 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

Re: Getting a set of lambda functions

2008-05-25 Thread Denis Kasak
On Sun, May 25, 2008 at 1:43 PM, Martin Manns [EMAIL PROTECTED] wrote: Hi, 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

Re: Getting a set of lambda functions

2008-05-25 Thread Scott David Daniels
Denis Kasak wrote: ... spam = [] for i in range(10): ... spam.append(lambda: i) spam[0]() 9 spam[1]() 9 Manually creating the lambdas and appending them to a list works as expected, naturally; I don't see a good reason why it wouldn't work with a loop. Am I missing something? Yes, you

Re: Getting a set of lambda functions

2008-05-25 Thread Denis Kasak
Scott David Daniels wrote: Denis Kasak wrote: ... spam = [] for i in range(10): ... spam.append(lambda: i) spam[0]() 9 spam[1]() 9 Manually creating the lambdas and appending them to a list works as expected, naturally; I don't see a good reason why it wouldn't work with a loop. Am I

Re: Getting a set of lambda functions

2008-05-25 Thread Martin Manns
On Sun, 25 May 2008 14:39:28 -0700 (PDT) [EMAIL PROTECTED] wrote: This may have some bugs left, but it looks a bit better: [...] self._hash = hash(self._func.func_code) ^ \ hash(tuple(signature[0]) + tuple(signature[1:3])) def __eq__(self, other):

Re: Getting a set of lambda functions

2008-05-25 Thread Terry Reedy
I V [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] | 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 I think it worth the reminder that Python has lambda *expressions* that result in function objects

Re: Getting a set of lambda functions

2008-05-25 Thread Terry Reedy
Martin Manns [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] | On Sun, 25 May 2008 14:39:28 -0700 (PDT) | [EMAIL PROTECTED] wrote: | | This may have some bugs left, but it looks a bit better: | [...] | self._hash = hash(self._func.func_code) ^ \ |

Re: Getting a set of lambda functions

2008-05-25 Thread John Nagle
Martin Manns wrote: Hi, 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). (The reason is that