美文网首页
python插入mysql文本内容包含引号等特殊符号的处理

python插入mysql文本内容包含引号等特殊符号的处理

作者: sexy_cyber | 来源:发表于2021-04-17 11:46 被阅读0次

用repr()最为科学,不影响数据的原始性

repr() 函数, 将对象转化为供解释器读取的形式。
repr() 返回一个对象的 string 格式。

比如

sql = f"insert into bh3_warning_result(id,url,content,source_channel_id,pub_time,keyword_type,job_type,update_time) values('{id}','{url}',{repr(content)},'{source_channel_id}',{pub_time},'{keyword_type}','{job_type}',now())"

其中要注意的是{repr(content)}外面不能加引号了

相关文章

网友评论

      本文标题:python插入mysql文本内容包含引号等特殊符号的处理

      本文链接:https://www.haomeiwen.com/subject/tjnelltx.html