%r

Blackbird fake at nospam.no
Mon Mar 6 18:13:21 EST 2006


Fredrik Lundh wrote:
> "Blackbird" <fake at 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.

By "cargo cult programming", do you mean actually *running* the code?
Noooo, no, no.  I *write* code.  I don't *run* code any longer.  A long life
has thought me that the awakenings you are in for, by running code, are rude
and only rude.

Blackbird





More information about the Python-list mailing list