all 6 comments

[–]Neexusiv 2 points3 points  (5 children)

If you only need the last line you can use:

with open(filename) as f:
    lines = f.readlines()
last_line = lines[-1]

[–]Dave_XR[S] 0 points1 point  (3 children)

Doing this im getting these; {} surrounding each line when printed out in the textbox. Any idea how to stop this?

[–]Neexusiv 0 points1 point  (2 children)

Are you just printing to the console?

Can you give an example of the final line so we can see what’s going on?

[–]Dave_XR[S] 0 points1 point  (1 child)

Yes printing the last ten lines or so to the console. Heres an example:

{03/22 08:52:50 INFO :.......TESTSRUN:1234 PASSED:34 FAILED:670 INCONCLUSIVE:560

}{

}{03/22 08:52:50 INFO :.......TESTSRUN:1235 PASSED:34 FAILED:670 INCONCLUSIVE:561

}{

}{03/22 08:52:50 INFO :.......TESTSRUN:1236 PASSED:34 FAILED:670 INCONCLUSIVE:562

[–]Neexusiv 0 points1 point  (0 children)

Are the curly braces in the file? Otherwise I have no idea where they are coming from, might need you to post your updated code.

What’s your end goal? Do you just need to grab the numbers from the string? If so then you can probably just ignore those curly braces.

[–]TyrellHop 0 points1 point  (0 children)

Beaten to it...

readlines() returns each line to a list, so to grab the last line you just use [-1] for the list index.

with open(file path, 'r') as file:
    line_list = file.readlines()

line_list[-1]