I need to split text before the second occurrence of the '-' character. What I have now is producing inconsistent results. I've tried various combinations of rsplit
and read through and tried other solutions on SO, with no results.
Sample file name to split: 'some-sample-filename-to-split'
returned in data.filename
. In this case, I would only like to have 'some-sample'
returned.
fname, extname = os.path.splitext(data.filename)
file_label = fname.rsplit('/',1)[-1]
file_label2 = file_label.rsplit('-',maxsplit=3)
print(file_label2,'\n','---------------','\n')