Re: %r
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: %r

From: Peter Hansen <peter@engcorp.com>
Date: Mon Mar 06 2006 - 23:49:59 CET

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
Received on Sun Apr 30 11:01:35 2006