In console:
def instance_repr(o):
if isinstance(o, list):
l = []
for i in o:
l.append( instance_repr(i) )
s = "[ %s ]" % ", ".join(l)
elif isinstance(o, str):
# TODO other control characters
s = str(o)
s = s.replace("'", "\\'")
elif isinstance(o, int):
s = str(o)
else:
s = o.__class__
return s
n = [ 1, 2, 3, 4 ]
print( instance_repr(n) )
n = [ "A", "B", "C", "D" ]
print( instance_repr(n) )
Result in:
[ 1, 2, 3, 4 ]
and the given error
For some strange reason, while dealing with the second test case,
it seems that the code ends up trying do perform an "append" on "A" string.
Notice that using an intermediate variable addresses the issue:
l.append( instance_repr(i) )
replaced by
x = instance_repr(i)
l.append(x)
Original issue reported on code.google.com by pedro.ro...@gmail.com on 30 Dec 2012 at 10:40
Original issue reported on code.google.com by
pedro.ro...@gmail.com
on 30 Dec 2012 at 10:40