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: Fredrik Lundh <fredrik@pythonware.com>
Date: Mon Mar 06 2006 - 17:59:11 CET

"Blackbird" wrote:
> I'm trying to get a complete grip on %r. Is it true that the two programs
>
> a = '*anything the parser accepts*'
> print '%r' % a
>
> vs.
>
> a = r'*anything the parser accepts*'
> print "'%s'" % a
>
> always produce the same output, where *anything the parser accepts* can be
> replaced with, well, anything the parser accepts?

no.

%s does a str() on the object (if it's not already a string), while
%r does a repr(). the raw string syntax has nothing to do with
this.

(see the builtin function section in the library reference for more
on str() and repr())

</F>
Received on Sun Apr 30 10:59:09 2006