Post #2753041
2024-02-08 16:16 UTC
@tmr232@mastodon.social The backslash DOES escape the closing quote in raw strings. That's why this behavior is preserved all the way to the last character in a string.
>>> print(r"A\"B")
A"B
Sure, it's a bit unexpected, and actively annoying for Windows paths. But it's weirdly consistent.
Replies (1)
-
@tmr232@mastodon.social 2024-02-08 18:27
@ambv@mastodon.social Oh, wow, I somehow missed that, even though this has bugged me for years... The thing is, it escapes the quote in a _very_ weird way. I just ran your example, and it prints: >>> print(r"A\"B") A\"B And... I never realized you can actually do that. So I always thought it's just a legacy tokenizer issue. But since it actually works inside a literal string, I guess it can't be changed...