PHP笔记网

革命尚未成功,同志仍须努力下载JDK17

作者:Albert.Wen  添加时间:2020-09-12 09:53:30  修改时间:2024-11-23 22:44:14  分类:10.Python基础  编辑
def string_addslashes(val):
    if isinstance(val, str):
        d = {"\0": "", " ": " ", "\\": "\\\\", "'": "\\'", "\"": "\\\"", "\r": "\\r", "\n": "\\n"}
        for x in d:
            val = val.replace(x, d.get(x))
        return "'" + val + "'"
        # return "'"+pymysql.escape_string(s)+"'"
    elif val is None:
        return "NULL"
    else:
        return "'" + str(val) + "'"