On 2024-10-07, Stefan Ram <[email protected]> wrote:
> "Michael F. Stemper" <[email protected]> wrote or quoted:
>>For now, I'll use the "r" in a cargo-cult fashion, until I decide which
>>syntax I prefer. (Is there any reason that one or the other is preferable?)
>
> I'd totally go with the r-style notation!
>
> It's got one bummer though - you can't end such a string literal with
> a backslash. But hey, no biggie, you could use one of those notations:
>
> main.py
>
> path = r'C:\Windows\example' + '\\'
>
> print( path )
>
> path = r'''
> C:\Windows\example\
> '''.strip()
>
> print( path )
>
> stdout
>
> C:\Windows\example\
> C:\Windows\example\
>
> .
... although of course in this example you should probably do neither of
those things, and instead do:
from pathlib import Path
path = Path(r'C:\Windows\example')
since in a Path the trailing '\' or '/' is unnecessary. Which leaves
very few remaining uses for a raw-string with a trailing '\'...
--
https://mail.python.org/mailman/listinfo/python-list