How to get the filename without the extension from a path in Python?

前端 未结 23 1861
逝去的感伤
逝去的感伤 2020-11-22 05:43

How to get the filename without the extension from a path in Python?

For instance, if I had "/path/to/some/file.txt", I would want "

23条回答
  •  迷失自我
    2020-11-22 06:43

    @IceAdor's refers to rsplit in a comment to @user2902201's solution. rsplit is the simplest solution that supports multiple periods.

    Here it is spelt out:

    file = 'my.report.txt'
    print file.rsplit('.', 1)[0]
    

    my.report

提交回复
热议问题