为 MySQL 转义字符串 Python
Unescape string Python for MySQL
我已经使用 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)))
我已经使用 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)))