【发布时间】:2017-07-07 13:04:28
【问题描述】:
我使用from MySQLdb import escape_string 来转义一个字符串。
如何取消转义字符串以取回原始字符串?
【问题讨论】:
我使用from MySQLdb import escape_string 来转义一个字符串。
如何取消转义字符串以取回原始字符串?
【问题讨论】:
与"your string".decode("string_escape")
>>> escaped_string = "Hello\\nThere"
>>>
>>> unescaped_string = escaped_string.decode("string_escape")
>>>
>>> escaped_string
'Hello\\nThere'
>>>
>>> unescaped_string
'Hello\nThere'
【讨论】:
我是这样做的
import ast
a = 'Hello\\nThere'
print(ast.literal_eval('"""{}"""'.format(a)))
【讨论】: