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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:45:23+00:00 2026-06-10T20:45:23+00:00

I wrote a program that merges several text files together, and from there, I

  • 0

I wrote a program that merges several text files together, and from there, I am trying to add dates to the first column using a for loop since there are several different dates. Using these loops though, the program doesn’t seem to iterate properly.

The supporting text files have a list of times without dates; however, each text file is associated with a different date. I am merging all of the text files together into one text file for easier use, though to make it useful, I am trying to add the dates to the times, which appears in the first column of the text file.

Here’s what the code looks like:

    import glob
    from datetime import *
    mon = [6, 7]
    dayrange1 = [24, 25, 26, 27, 28, 29, 30]
    dayrange2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

    m = 0
    d1 = 0
    d2 = 0
    newline = []



    fout = open("C:\\Users\\jessica.macleod\\Desktop\\SurmontArray1.txt", "a")
    for filename in glob.glob("C:\\Users\\jessica.macleod\\Desktop\\Surmont Noise Files\\s1-424surmontnoise2012*.txt"):
        f = open(filename)
        f.next()
        f.next()
        d1 = 0
        d2 = 0
        for months in mon:

            if m == 0:

                for days in dayrange1:

                    for line in f:
                        line += str(date(2012, mon[m], dayrange1[d1])) + " "
                        fout.write(line)
                    d1 = d1 + 1
                m = m + 1


            if m == 1:

                for days in dayrange2:

                    for line in f:
                        line += str(date(2012, mon[m], dayrange2[d2])) + " "
                        fout.write(line)
                    d2 = d2 + 1




        f.close()
    fout.close()
  • 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-10T20:45:25+00:00Added an answer on June 10, 2026 at 8:45 pm

    dayrange1 is not iterated over in the second loop of for months in mon because you have set m to 1. It is skipped because it is guarded by the conditional if m == 0:. This means that only the very first matched filename in your glob will have the results of iterating over dayrange1. You’ll need to reset m to 0 inside of one of your loops.

    Also, you iterate over days in daterange1. During the first iteration of that loop you iterate over the entire contents of f. That means on the second iteration over daterange1 the file is used up.

    Also, you don’t use days inside of your loop.

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

Sidebar

Related Questions

I wrote a program that downloads some files from some servers. Currently program works
I wrote a program that accepts and outputs Hebrew (i.e. right-to-left) text. In lieu
I wrote a program that is based completely on a single text file: I
I've wrote a program that gets from the user a number, and then gets
I wrote a program that worked perfectly until the market required me to add
I wrote a program that captures Ethernet packets from some NIC (i.e eth0) at
I wrote one program that load a text file. it work well. I try
I wrote a program that solves mazes with depth-first search. I was wondering how
I'm trying to write a program that merge two or more .dat files in
I wrote a simple program that receives several inputs and it does a future

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.