Check if a variable is SRE_Match

前端 未结 5 1726
自闭症患者
自闭症患者 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:53

    Pile-on, since there's a whole bunch of ways to solve the problem:

    def is_match_obj(m):
        t = type(m)
        return (t.__module__, t.__name__) == ('_sre', 'SRE_Match')
    

提交回复
热议问题