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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:57:35+00:00 2026-06-02T05:57:35+00:00

Clarification: So if my file has 10 lines: THe first line is a heading,

  • 0

Clarification:
So if my file has 10 lines:
THe first line is a heading, so I want to append some text at the end of first line

THen I have a list which contains 9 elements..

I want to read that list and append the end of each line with corresponding element..

So basically list[0] to second line, list[1] to third line and so on..


I have a file which is delimted by comma.
something like this:

A,B,C
0.123,222,942
......

Now I want to do something like this:

A,B,C,D #append "D" just once
0.123,222,942,99293
............   

This “D” is actually saved in a list so yeah I have this “D”
How do I do this? I mean I know the naive way.
like go thru each line and do something like

string += str(list[i])

Basically how do i append something at the end of the file in pythonic 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-06-02T05:57:38+00:00Added an answer on June 2, 2026 at 5:57 am

    Just create a new file:

    data = ['header', 1, 2, 3, 4]
    
    with open("infile", 'r') as inf, open("infile.2", 'w') as outf:
        outf.writelines('%s,%s\n' % (s.strip(), n) for s, n in zip(inf, data))
    

    If you want to “update” the input file, just rename the new one afterwards

    import os
    os.unlink("infile")
    os.rename("infile.2", "infile")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 1.3GB text file that I need to extract some information from
I need some clarification. I have a Reportwriter dll that uses Crystal Reports. It
I just need some clarification on variables A normal variable has 2 parts to
What's the best way to return a random line in a text file using
I need some clarification; I have a jar that I built and inside of
I'm looking for a perfect text editor :) The must have list: vim-like modal
I currently have a CSV file which, when opened in Excel, has a total
I need clarification in calling methodologies, i have a base class and from which
I have a custom file format for graphs which looks like this: node1.link1 :
I would like to convert specific ascii file to csv. This ascii file has

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.