Just a quick correction, in case a begginer sees this thread. You can use raw strings for Windows paths, except when they end with a backslash.
This works: path = r'somewhere\some\folder' filepath = r'somewhere\some\folder\file.txt'
This also works: from os import sep path = r'somewhere\some\folder' + sep
This doesn't work: path = r'somewhere\some\folder'
On 22/02/2020 06:26, Steven D'Aprano wrote:
On Fri, Feb 21, 2020 at 10:19:37PM -0500, David Mertz wrote:
On Fri, Feb 21, 2020 at 9:26 PM Steven D'Aprano email@example.com wrote:
And what's so special about SQL over, say, regular expressions, XML, JSON, YAML, Markdown, ReST, LaTeX, etc? I might want to use the s'' prefix for embedded Scheme code rather than SQL.
Um, regular expressions are not precisely the best example there, since we do have raw strings specifically for regular expressions.
I mentioned them also in my similar list, but deliberately. *Raw strings* are not per-se for regexen, even if that is one of the more common uses.
Actually, in Python, regexes are the primary reason raw strings were added!
Raw strings aren't quite fully raw, which is why you can't use raw strings for Windows paths:
path = r'somewhere\some\folder\'
doesn't work. The reason is that "raw" (semi-cooked?) strings are intended for regexes, not as a general mechanism for disabling string escape codes, and regexes aren't allow to end with a bare backslash.