[Tutor] Tutor Digest, Vol 33, Issue 48

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Sun Nov 12 04:41:17 CET 2006


>> What was the bug?
>
> If the stringifier saw two instances of the same object, it'd think that 
> recursion was going on.  Unfortunately, since the numbers between 1-100 
> are typically interned (as well as strings), it'd also think that if I 
> visited "0" twice,that I was in a recursive loop too.

The test cases from the bottom of:

     http://hashcollision.org/svn/repos/projects/misc/deepstr/deepstr.py

especially testRepeatedObjects() and testNonRecursion(), failed with the 
older code.  The way I'm doing it now is much better, even though it's 
still very subtle.

I like the code though, just because it isolates the hard part about 
writing a function like this.  Once we have DeepStr, the implementation of 
the deep_str function is simple.  Of course, all of this is already 
implemented deep in the bowels of Python already, but I wanted to make 
something extensible.

Anyway, thanks again for the feedback; I'm considering this a done project 
for now.  *grin*


More information about the Tutor mailing list