%r
Peter Hansen
peter at engcorp.com
Mon Mar 6 17:49:59 EST 2006
Blackbird wrote:
> a = 'something'
> b = ('%r'%a)
> eval(b) == a
>
> that in general should return True. I hope. But I'm sure there are
> counterexamples to that, too.
Provided 'something' is a string, that should be true, as should the
simpler statement a == eval(repr(a)) (since '%r' is just a more complex
way of getting the same thing as repr()).
On the other hand, if 'something' is actually some arbitrary object,
then it's definitely not always true, especially for anything not built
in to Python.
-Peter
More information about the Python-list
mailing list