Ajay Ajay - 2 months ago 15
Python Question

stripslashes issue

I'm trying to condense/improve/optimize this code

cleaned = stringwithslashes
cleaned = cleaned.replace("\\n", "\n")
cleaned = cleaned.replace("\\r", "\n")
cleaned = cleaned.replace("\\", "")


but the above code does not work correctly

Answer

try this

cleaned = stringwithslashes.decode('string_escape')