You can remove the last line of a string like this:
def remove_last_line_from_string(s):
return s[:s.rfind('\n')]
string = "String with\nsome\nnewlines to answer\non StackOverflow.\nThis line gets removed"
print string
string = remove_last_line_from_string(string)
print '\n\n'+string
The output will be:
>>>
String with
some
newlines to answer
on StackOverflow.
This line gets removed
String with
some
newlines to answer
on StackOverflow.
>>>