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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:58:50+00:00 2026-05-31T08:58:50+00:00

Hi experts I’m looking to make a loop of reading a text file then

  • 0

Hi experts I’m looking to make a loop of reading a text file then output (8) text files with the following code:

for i in range(1,9):
    with open(inputgui, 'r') as input1:
        junkinfo = [next(input1) for dummy in range(22)]
        with open(output, 'w') as output1:
            for line in input1:
                columns = line.strip().split()
                output1.write('{:8}{:8}\n'.format(columns[1], columns[i+1]))

Note that variable inputgui is a text variable from a user and output is a text variable from a user. Example, the user in the gui will select 'C:/Data.txt' and will want to name the output and iterate 8 times to produce 'C:/NewData1.txt', 'C:/NewData2.txt', etc. How do I format variable output to iterate or most efficient way?

  • 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-05-31T08:58:51+00:00Added an answer on May 31, 2026 at 8:58 am

    Assuming that the user provides a file name with a .txt extension you can do this:

    for i in range(1,9):
        with open(inputgui, 'r') as input1:
            junkinfo = [next(input1) for dummy in range(22)]
    
            newOutput = output[:-4] + str(i) + output[-4:]
    
            with open(newOutput, 'w') as output1:
                for line in input1:
                    columns = line.strip().split()
                    output1.write('{:8}{:8}\n'.format(columns[1], columns[i+1]))
    

    If the extension is unknown you will need to find where the . is and splice based on its location

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

Sidebar

Related Questions

To those jQuery experts out there. I have the following markup and code: <html>
you experts probably knowing the easyiest ways to open/find a file from asp.net mvc
Experts - I need some advice in the following scenario. I have a configuration
Hi experts am trying to parse an excel file. its structure is very complex.
Are there any regex experts who can help me clean up the following source
This question is for Mysql geospatial-extension experts. The following query doesn't the result that
Experts, I have JQGrid with custom template column like Edit. the following screen display
Experts, The following function are successfully send data to the Controller.cs (server) var ajaxResponse
CUDA experts, if I have defined in the host code a new type: struct
Hi experts please see this code: <asp:UpdatePanel ID=UpdatePanel1 runat=server UpdateMode=Conditional> <ContentTemplate> <table border=1 cellpadding=8

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.