"elventear" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Hello everyone, | | I am runing into recursion limit problems. I have found that the | culprit was related to the __hash__ function that I had assigned to | the objects that were added to a set. | | Basically my __hash__ function is the following: | | def __hash__(self): | out_int = 0 | for property,value in self: | out_int ^= hash( property )^hash( value ) | | return out_int | | And the iterator for this object is: | | def __iter__(self): | for property,value in self.__dict__.iteritems(): | yield property,value | | After commenting the __hash__ function and using the default provided | by Python (I suppose it is based on the position in memory of the | object), the recursion limit problems went away. (This problem was | happening even after increasing the recursion limit to the maximum of | my platform, MacOSX). | | I am not that versed in Python, so I don't know exactly I could do to | overcome this problem, any ideas are deeply appreciated.
Without seeing the full code and the exception traceback, my guess is that your __hash__ somehow calls itself due to a refence loop in your object. A simple example of a loop: a = []; a.append(a) Now, list objects are not hashable, but if they were, and the hash were value based (like your), then hash(a) would call hash(a) would call hash(a).... Suggestion: put print id(self) in __hash__ and see if you get a repeat. And maybe reduce the recursion limit to reduce the traceback listing ;-) Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list