I have a program which let the user input som data which then get drawn on the canvas (like a weekly scheme).
I now want the user to be able to delete or redo an entry (which i will do by a click event), however, my question goes:
How do i read a specific line in my textfile? A sample of a possible textfile:
Abe
#0080c0
February
Friday
21
Part delivery
John
#ff8000
July
Sunday
21
Social
Egon
#ff80ff
April
Thursday
15
Work
Note that this is a small part of the textfile, ideally it would contain 56 of theese 6-line-clusters.
my code for inserting the text:
taskentry = str(tasknameentry.get())
monthentry = str(monthvar.get())
dayentry = str(dayvar.get())
dateentry = str(datevar.get())
activityentry = str(typevar.get())
tasklist = [taskentry, hexstr, monthentry, dayentry, dateentry, activityentry]
taskfile = open('taskfile.txt', 'a')
for word in tasklist:
taskfile.write('%s \n' % word)
taskfile.write('\n')
taskfile.close()
So for the user to be able to redo or delete a “task” i need to read the file and look for a specific task name or something similar, im just not sure how to. I’ve read through the .write and .read part of my book, looked at the docs and questions here but havent been able to produce a valid solution.
What i need now, so i can move on is just a way to read fx the 6 appending lines when searching for fx John. So i in the future can have a redo or delete event choosen by a click.
In advance, thanks!
Best regards,
Casper
If the file is not that big, you can read the file into a buffer, modify that buffer and write the buffer back to the file. A quick code snippet would be like: