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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:20:36+00:00 2026-06-06T00:20:36+00:00

From a file, i have taken a line, split the line into 5 columns

  • 0

From a file, i have taken a line, split the line into 5 columns using split(). But i have to write those columns as tab separated values in an output file.

Lets say that i have l[1], l[2], l[3], l[4], l[5]…a total of 5 entries. How can i achieve this using python? And also, i am not able to write l[1], l[2], l[3], l[4], l[5] values to an output file.

I tried both these codes, both not working(i am using python 2.6):

code 1:

with open('output', 'w'):
   print l[1], l[2], l[3], l[4], l[5] > output

code 2:

with open('output', 'w') as outf:
   outf.write(l[1], l[2], l[3], l[4], l[5])
  • 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-06T00:20:38+00:00Added an answer on June 6, 2026 at 12:20 am

    You can use a parameter in the with statement representing the file you’re writing to. From there, use .write(). This assumes that everything in l is a string, otherwise you’d have to wrap all of them with str().

    with open('output', 'w') as f:
        f.write(l[1] + "\t" + l[2] + "\t" + l[3] + "\t" + l[4] + "\t" + l[5] + "\n")
    

    Alternatively, and more efficiently, you can use .join():

    with open('output', 'w') as f:
        f.write('\t'.join(l[1:]) + '\n')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file from which i read line by line and i have
I have written java code for generating json of my searched data from file.But
I have a cpp file from which I am generating a shared library (using
i have been using an actionListener to pass text from numerous TextFields into a
I have code to read in the version number from a make file. VERSION_ID=map(int,re.match(VERSION_ID\s*=\s*(\S+),open(version.mk).read()).group(1).split(.))
I have an embedded iframe form which takes a file from a type=file form
I have a homework assignment where I need to take input from a file
I have a file, myfile.py , which imports Class1 from file.py and file.py contains
I would like to update an xml file from another xml file.I have used
I have a file from bank that is structure in very special way. Where

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.