Extracting extension from filename in Python

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

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

24条回答
  •  自闭症患者
    2020-11-22 14:19

    A true one-liner, if you like regex. And it doesn't matter even if you have additional "." in the middle

    import re
    
    file_ext = re.search(r"\.([^.]+)$", filename).group(1)
    

    See here for the result: Click Here

提交回复
热议问题