I'd like to convert a string in Python to a raw string, doing this programmatically. To say it short, I'd like to add a "r" before my string with a function.
In my case, this is a windows path, like this:
path = "C:\my path\01 with numbers in folder names\02 and\next folder"
The easy way is to write "r" or "R" to read the string as raw, like this:
path = r"C:\my path\01 with numbers in folder names\02 and\next folder"
But I'll get the path from the user, and I want to convert it on the fly to raw before something else happens (in my case I want to convert it to a unix path).
How to do it? Is it really true it is not possible? The only working function I found is this one, but it is quite cumbersome, because it needs a hard coded dictionary.
UPDATE/SOLUTION: This behavior only happens if the string is coming from the python code itself. Reading this string from a gui (e.g. pyside2), it remains as raw string.
print(self.ui.plainTextEdit.toPlainText())
-> C:\my path\01 with numbers in folder names\02 and\next folder