Let's say I have a raw string like r'\n'
that corresponds to '\\n'
. Is there a way to interpret the raw string as the "normal" string '\n'
with the line break meaning?
Asked
Active
Viewed 633 times
-2

Bharath M Shetty
- 30,075
- 6
- 57
- 108

bluePhlavio
- 537
- 5
- 18
-
2`r'\n'.replace("\\n", "\n")`? – Christian König Jul 27 '17 at 10:09
-
1Maybe a dupe of https://stackoverflow.com/questions/1885181/how-do-i-un-escape-a-backslash-escaped-string-in-python ? – Wiktor Stribiżew Jul 27 '17 at 10:09
-
Note that there is no such thing as a "raw string" in Python - there is only a "raw string literal". `a=r'\n'; b='\\n'` ... leaves `a` and `b` with identical contents. – Martin Bonner supports Monica Jul 27 '17 at 10:16
-
@WiktorStribiżew : You can vote to close with that as duplicate you know. – Martin Bonner supports Monica Jul 27 '17 at 10:18
-
@MartinBonner I voted to close as unclear. As it is both unclear, and seems to be a dupe. – Wiktor Stribiżew Jul 27 '17 at 10:23
-
Ah! Fair enough. Well, he's got one of each now. – Martin Bonner supports Monica Jul 27 '17 at 10:29