Python – search txt.file for ID, then return variable from line below

In Python, I’m attempting (very poorly) to read a .txt file, find the last occurrence of a string referencing a particular customer, and read a few lines below that to gain their current points balance.

A snapshot of the .txt file is:

**Customer ID:123
Total sale amount:2345.45

Points from sale:23
Points until next bonus: 77**

I can search for (and find) the specific Customer ID, but can’t figure out how to search for the last occurrence of this ID only, or how to return the ‘Points until next bonus’ value… I apologise if this is a basic question, but any help would be greatly appreciated!

Source: python

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.