Check if a variable is SRE_Match

前端 未结 5 1725
自闭症患者
自闭症患者 2021-01-19 02:30

I need to check if a variable is a regular expression match object.

print(type(m)) returns something like that: <_sre.SRE_Match object at 0x000

5条回答
  •  北恋
    北恋 (楼主)
    2021-01-19 02:47

    You can do

    SRE_MATCH_TYPE = type(re.match("", ""))
    

    at the start of the program, and then

    type(m) is SRE_MATCH_TYPE
    

    each time you want to make the comparison.

提交回复
热议问题