我正在尝试压缩/改进/优化此代码
cleaned = stringwithslashes
cleaned = cleaned.replace("\\n", "\n")
cleaned = cleaned.replace("\\r", "\n")
cleaned = cleaned.replace("\\", "")
但上面的代码无法正常工作
答案 0 :(得分:1)
对于初学者,您的代码缺少引号。你试过这个吗?
cleaned = stringwithslashes
cleaned = cleaned.replace("\\n", "\n")
cleaned = cleaned.replace("\\r", "\n")
cleaned = cleaned.replace("\\", "")
答案 1 :(得分:0)
试试这个
cleaned = stringwithslashes.decode('string_escape')