Best practise implementation for equal by value objects

Duncan Booth duncan.booth at invalid.invalid
Thu Aug 7 04:07:04 EDT 2008


Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> wrote:

> I believe the recommendation for eval(repr(obj)) to give obj again is 
> meant as a convenience for the interactive interpreter, and even there 
> only for simple types like int or list.


and even with types as simple as list and int the round tripping can easily 
fail:

>>> lst = [1, 2, 3]
>>> lst[1] = lst
>>> eval(repr(lst))

Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    eval(repr(lst))
  File "<string>", line 1
    [1, [...], 3]
         ^
SyntaxError: invalid syntax

-- 
Duncan Booth http://kupuguy.blogspot.com



More information about the Python-list mailing list