Ajay Ajay - 1 year ago 65
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')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download