Extracting extension from filename in Python

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

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

24条回答
  •  庸人自扰
    2020-11-22 14:20

    import os.path
    extension = os.path.splitext(filename)[1][1:]
    

    To get only the text of the extension, without the dot.

提交回复
热议问题