返回python在re模块中搜索和匹配的类型?

2024-04-18 15:44:20 发布

您现在位置:Python中文网/ 问答频道 /正文

记录方法的返回类型,我有:

@classmethod
def rightFileType(cls, fileName):
    """Check if the filetype (extension) is correct for subclass.
    :type fileName: str | unicode
    :rtype: _sre.SRE_Match | None # here ?
    """
    return cls.file_extension.search(fileName)

使用私有模块是不对的,但是文档引用了一个我在re.MatchObject中找不到的re类,pycharm无法解析这个符号。所以这里是关于MatchObject在python的re模块中-或者我应该在这里使用什么作为返回类型?你知道吗


Tags: 模块the方法re类型ifdefcheck
1条回答
网友
1楼 · 发布于 2024-04-18 15:44:20

我想您应该返回布尔类型。 然后:

if cls.file_extesion.search(fileName):
    return True
return False

但是,我不知道为什么在这里使用regex,可以用strendswith方法检查文件名。你知道吗

相关问题 更多 >