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 - 18:24:42 CET

"Blackbird" <fake@nospam.no> wrote:

> >> [...]
> >
> >>>> a = 'I don\'t think so'
> >>>> print '%r' % a
> > "I don't think so"
> >>>> a = r'I don\'t think so'
> >>>> print "'%s'" % a
> > 'I don\'t think so'
>
> Excellent counterexample. Can something like this happen for other things
> than quotes?

>>> a = '\377'
>>> print '%r' % a
'\xff'
>>> a = r'\377'
>>> print "'%s'" % a
'\377'

I still recommend looking up %s and %r and str() and repr() in the
documentation. it's not hard to understand what they do, and that
approach works a bit better than cargo cult programming.

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