不灭的焱

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

作者:php-note.com  发布于:2020-09-12 09:52  分类: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) + "'"