检查变量是否为 SRE_Match [英] Check if a variable is SRE_Match
本文介绍了检查变量是否为 SRE_Match的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要检查一个变量是否是正则表达式匹配对象.
I need to check if a variable is a regular expression match object.
print(type(m))
返回类似的内容:<_sre.SRE_Match 对象在 0x000000000345BE68>
但是当我导入 _sre
并尝试执行 type(m) is SRE_Match
异常 NameError: name 'SRE_Match' is not defined
被提出.
but when I import _sre
and try to execute type(m) is SRE_Match
the exception NameError: name 'SRE_Match' is not defined
is raised.
推荐答案
你可以做
SRE_MATCH_TYPE = type(re.match("", ""))
在程序开始时,然后
type(m) is SRE_MATCH_TYPE
每次您想要进行比较时.
each time you want to make the comparison.
这篇关于检查变量是否为 SRE_Match的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文