Can a simple a==b 'hang' in and endless loop?
steve at holdenweb.com
Thu Jan 19 06:24:57 EST 2006
Claudio Grondi wrote:
> Steven D'Aprano wrote:
>>Claudio Grondi wrote:
>>>Exactly this is what Python does under the hood when writing
>>>a = "some string"
>>>b = "some string"
>>>where a and b are actually, in terms of C, pointer to Python object
>>>data structures which provide strings as arrays where it is possible
>>>to say a, but ... if here
>>> print "True"
>>>_does not_ print True, the Python engine is definitely broken.
>>Why are you comparing C behaviour to Python behaviour? What is the point
>>of the discussion?
> The point is to find a way to create in Python two indentifiers a and b
> without manipulating any of the __eq__ and to __eq__ related functions
> in a way, that the simple
> if a==b: print 'a==b'
> statement results in an endless loop.
> To my knowledge this is not possible to achieve in C, but is probably
> achievable in Python.
So finally we understand what you are looking for (though not why ...).
>>> a = 
>>> b = 
>>> a == b
Traceback (most recent call last):
File "<stdin>", line 1, in ?
RuntimeError: maximum recursion depth exceeded in cmp
Is this what you seek? Not quite "an endless loop", but probably as
close as you are going to get given the necessariliy recursive data
structures required to induce it.
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
More information about the Python-list