I have a text file with lines like this:
[00451] Kayle - 2/3/15 - Win - 2012-11-22
the number between the brackets [ ] at the start is an id number, I need to get that from the last line of the file (or a string passed containing that line) so I can increment it for writing more lines to the file so every game record will have a unique id number. I’ve been trying for a while with split, strip, and regex, but I can’t seem to get it to work. Can anyone help? I could just use lines of the file to do this maybe but I wanted to be able to re-sort the file later on by id, name, or other criteria.
My data written to the file in my other code looks like this:
data = "[%s] %s - %s/%s/%s - %s - %s\n" % (id, champname, kills, deaths, assists, winloss, timestamp)
How can I get the id of the last line so I can increment future appends id?
Here’s a regular expression solution: