I have this in my file:
2023-09-08 10:40:04 twitter
2023-09-08 10:40:05 sreality
I need to get first and second text from the last line.
I tried this but it get only text before first space:
with open("mujlist.txt", "r") as file:
lines = file.readlines()
if not lines:
print("There is nothing in your file")
else:
last_line = lines[-1].split(' ', 2)[0].strip()
print(last_line)
Do you have some idea what to change to get: 2023-09-08 10:40:05 ?
Thank you
If your text-file is relatively large, you might want to consider reading it from the end :
Output :