repr(x) == repr(y) <=> x == y AND eval(repr(x)) == x

Thorsten Kampe thorsten at
Fri Oct 18 21:09:47 CEST 2002


I'm using dictionaries for some "very generalized programs". This
means that I cannot tell in advance if all the items I'm operating on
are hashable. The "trick" that came to my mind was to use repr(x) as
the key (instead of x).

This relies on two assumptions:

1. repr(x) == repr(y) <=> x == y

2. eval(repr(x)) == x (for further processing)

A wise man once said to me:
| You're FAR more likely to meet objects where you can't count on
| eval(repr(x)) == x, than non-hashable objects.

Does anyone know under which circumstances 1. and 2. are wrong?


More information about the Python-list mailing list