PHP的striplashes的Python版本

我编写了一段代码将PHP的striplashes转换为有效的Python [反斜杠]转义:

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

我怎么能压缩它?

解决方法:

不完全确定这是你想要的,但..

cleaned = stringwithslashes.decode('string_escape')
上一篇:Java单例和多例


下一篇:密码包含&符号时,php ldap_bind失败