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 8768223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:00:59+00:00 2026-06-13T17:00:59+00:00

i = 1 # keep track of file number directory = ‘/some/directory/’ for i

  • 0
i = 1 # keep track of file number
directory = '/some/directory/'


for i in range(1, 5170): #number of files in directory
    filename = directory + 'D' + str(i) + '.txt'
    input = open(filename)
    output = open('output.txt', 'w')
    input.readline() #ignore first line
    for g in range(0, 7): #write next seven lines to output.txt
        output.write(input.readline())

    output.write('\n') #add newline to avoid mess
    output.close()
    input.close()
    i = i + 1

I have this code, and i am trying to get one file and rewrite it to output.txt, but when i want to attach next file, my code overwrite older file that has been attached. In result when code is complete i have something like this:

dataA[5169]=26
dataB[5169]=0
dataC[5169]=y
dataD[5169]='something'
dataE[5169]=x
data_date[5169]=2012.06.02

Instead of datas ranging from files 0 to 5169. Any tips how to fix it?

  • 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-13T17:01:00+00:00Added an answer on June 13, 2026 at 5:01 pm

    Your issue is that you open in write mode. To append to file you want to use append. See here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using IO::Select to keep track of a variable number of file handles
Does RTC source control store a file to keep track of projects. In clearcase
I need to keep track of number of hits on a particular item in
My professor, (for some unexplained reason) wants to change all input-output files of our
All I'm doing is trying to keep track of the number of times a
I need to keep track of around 10000 elements of an array in my
How do I keep track of the position of a UI element, say a
I need to keep track of how many items are in a node of
How can you keep track of time in a simple embedded system, given that
I am looking to keep track of people in my iPhone app - either

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.