How can I escape the backslashes in the string: 'pictures\12761_1.jpg'
?
I know about raw string. How can I convert str to raw if I take 'pictures\12761_1.jpg'
value from xml file for example?
You can use the string .replace()
method along with rawstring.
Python 2:
>>> print r'pictures\12761_1.jpg'.replace("\\", "/")
pictures/12761_1.jpg
Python 3:
>>> print(r'pictures\12761_1.jpg'.replace("\\", "/"))
pictures/12761_1.jpg
There are two things to notice here:
I know the second part is bit confusing but I hope it made some sense.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With