Skip to main content
2 of 2
refactor for brevity
mirekphd
  • 7.2k
  • 4
  • 62
  • 89

As noted by @IceAdor in a comment to @user2902201's solution, rsplit is the simplest solution robust to multiple periods (by limiting the number of splits to maxsplit of just 1 (from the end of the string)).

Here it is spelt out:

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

my.report

dlink
  • 1.6k
  • 19
  • 23