r"string" vs R"string

Terry Reedy tjreedy at udel.edu
Mon Jan 18 17:12:28 EST 2010


On 1/18/2010 8:01 AM, Colin W. wrote:
> On 17-Jan-10 18:27 PM, Steven D'Aprano wrote:
>> On Sun, 17 Jan 2010 11:13:48 -0500, Roy Smith wrote:
>>
>>> In article<hiv4c6$5l8$1 at theodyn.ncf.ca>,
>>> "Colin W."<cjwilliams43 at gmail.com> wrote:
>>>
>>>> On 17-Jan-10 02:16 AM, Terry Reedy wrote:
>>>>> On 1/17/2010 1:55 AM, Brendan Miller wrote:
>>>>>> Is there any difference whatsoever between a raw string beginning
>>>>>> with the captical R or one with the lower case r e.g. r"string" vs
>>>>>> R"string"?
>>>>>
>>>>> No. Nor is there and difference between the strings created with raw
>>>>> literals and cooked literals.
>>>>>
>>>>>
>>>> "cooked" literal ??
>>>
>>> I've never seen it referred to this way in the Python literature, but
>>> "cooked" is a well-known term meaning, "not raw". The usage goes back
>>> decades.
>>
>> I think the use of "cooked" meaning "not raw" goes back a little bit more
>> than decades. The verb "to cook" dates from the late 14th century, and
>> the adjective form "cooked" would follow soon after. The use of "cooked"
>> to mean manipulated (as in "cooking the books") comes from the 1630s.
>> Extending it to strings (as in raw versus cooked strings) is an obvious
>> extension.
>>
> Yes, I should have cottoned on, but perhaps "... between the strings,
> raw and other." would have conveyed the idea.

I intentionally did not say that because Python only has one type of 
string object (in 3.x), not raw and normal. Python *code* has string 
literals optionally prefixed with 'r' (or 'R', which I did not know 
before) to suppress the normal processing that reduces escape sequences 
to one char.

The term 'cooked' versus 'raw' was used in Unixland at least through the 
1980s. For instance, the input stream from a terminal could be cooked or 
left raw. I presume that is whence came Python's use of 'raw', with much 
the same meaning.

Terry Jan Reedy




More information about the Python-list mailing list