[英]Suppress specific warning message
First, when doing an INSERT IGNORE
, why does pymysql
return a warning?首先,在执行
INSERT IGNORE
,为什么pymysql
返回警告?
/python3.6/site-packages/pymysql/cursors.py:170: Warning: (1062, "Duplicate entry '2175891' for key 'PRIMARY'")
/python3.6/site-packages/pymysql/cursors.py:170:警告:(1062,“重复条目 '2175891' 键'PRIMARY'”)
And second, is there a way to suppress these warnings?其次,有没有办法抑制这些警告? What I currently have is:
我目前拥有的是:
warnings.filterwarnings("ignore", category=pymysql.Warning)
Yet, I don't want to suppress all the pymysql
warnings, only this one that seems a bit misplaced.然而,我不想抑制所有
pymysql
警告,只有这个似乎有点放错pymysql
警告。
Use the message parameter.使用消息参数。 It accepts a regex:
它接受一个正则表达式:
warnings.filterwarnings(
action="ignore",
message=".*Duplicate entry.*",
category=pymysql.Warning
)
message is a string containing a regular expression that the start of the warning message must match.
message是一个字符串,其中包含警告消息的开头必须匹配的正则表达式。 The expression is compiled to always be case-insensitive.
表达式被编译为始终不区分大小写。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.