Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9049803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:29:34+00:00 2026-06-16T12:29:34+00:00

I have a program which let the user input som data which then get

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T12:29:37+00:00Added an answer on June 16, 2026 at 12:29 pm

    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:

    #open the file
    f = open('file.txt')
    lines = f.readlines()
    lineNum = -1
    
    #find the line to modify
    for i, line in enumerate(lines):
        if line.strip() == "John":
            lineNum = i
            break
    
    if lineNum == -1:
        #Line not found, handle the error..
    
    #modify the buffer with the new data
    newtasklist = [taskentry, hexstr, monthentry, dayentry, dateentry, activityentry]
    for task in newtasklist:
        lines[lineNum] = task
        lineNum += 1
    
    #or if you want to remove the task list :
    lines = lines[:lineNum] + [lineNum + 7:]
    
    # and write everything back
    with open('file.txt', 'w') as file:
        file.writelines(lines)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program where I need the user to input data in a
I have a C# console program which main functions should let a user grep
Simple synopsis: I have a program which needs authentication from user to get access
I have a program which creates JButtons which are then added to a JPanel
I have a program which I would like to run every X min the
I have a program which takes a long time to complete. I would like
I have a little program, let's call it program by simplicity which has normal
let say i have send email program which need to run arround 7 hours.
I have written a program in C which lets the user enter a password
I have a program which dynamically generates a GUI. I don't know how many

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.