Ajay Ajay - 6 months ago 33
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 Source

try this

cleaned = stringwithslashes.decode('string_escape')