I'm creating an online bank program. The users recent transactions are stored in a logs file. The user has the ability to display their log file to see recent transactions. I have managed to get the program to print the file but I need to remove the formatting and separate each log onto separate lines
What the user currently gets printed
['01-01-2020 22:02: Moved £564 from balance to savings\n', '02-01-2020 01:11: Moved £345 from savings to balance\n']
What I need to be printed
01-01-2020 22:02: Moved £564 from balance to savings
02-01-2020 01:11: Moved £345 from savings to balance
Code for reading the file
def log_show(id):
with open(id + " log.txt", 'r') as log:
logs = log.readlines()
print(logs)
log.close()
Example for writing a transaction to the file
with open(data["ID"] + " log.txt", "a") as log:
log.write(now.strftime("%d-%m-%Y %H:%M") + ": Moved £"+ str(amount) + " from balance to savings\n")
The only way I've though I could do it is by reading each line separately then slicing the formatted parts of the end, but unsure how I can do this
Any suggestions?
Thanks