You gotta love a 2-line python solution
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Mon May 2 01:51:53 EDT 2016
On Monday 02 May 2016 15:21, Stephen Hansen wrote:
> On Sun, May 1, 2016, at 10:08 PM, DFS wrote:
>> On 5/2/2016 1:02 AM, Stephen Hansen wrote:
>> >> I actually use "D:\\file.html" in my code.
>> >
>> > Or you can do that. But the whole point of raw strings is not having to
>> > escape slashes :)
>>
>>
>> Nice. Where/how else is 'r' used?
>
> Raw strings are primarily used A) for windows paths, and more
> universally, B) for regular expressions.
Raw strings are designed for regular expressions. They can be used for
Windows paths, except for one minor gotcha: you can't end a raw string with
an odd number of backspaces. So this doesn't work:
directory = r'D:\some\path\dir\'
So it's more of a half-cooked string than a raw string.
--
Steve
More information about the Python-list
mailing list