Extracting extension from filename in Python

后端 未结 24 2381
感情败类
感情败类 2020-11-22 13:23

Is there a function to extract the extension from a filename?

24条回答
  •  青春惊慌失措
    2020-11-22 14:12

    Even this question is already answered I'd add the solution in Regex.

    >>> import re
    >>> file_suffix = ".*(\..*)"
    >>> result = re.search(file_suffix, "somefile.ext")
    >>> result.group(1)
    '.ext'
    

提交回复
热议问题