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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:34:23+00:00 2026-05-25T21:34:23+00:00

I want to create a text file which contains a table, created from lists.

  • 0

I want to create a text file which contains a table, created from lists. But, I don’t want to have to do something like this:

import string
print >> textfile, string.rjust(listname[0],3), string.rjust(listname[1],3),

The following code demonstrates the idea of what I would like to do, but doesn’t work:

import string
listname = ['test1','test2','test3']
i=0
for i in range(0,3):
   print >> textfile, string.rjust(listname[i],5)

I would like the output to look exactly like this:

test1   test2   test3

That’s what I’m trying to do and how it makes sense in my head, but obviously that won’t (and isn’t) working.

I’ve used the join() function to print the lists nicely, but I can’t get the spacing right for the table.

Any ideas?

  • 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-25T21:34:23+00:00Added an answer on May 25, 2026 at 9:34 pm

    If I’m understanding the problem correctly, you could just do this…

    >>> def print_table():
    ...     headers = ['One', 'Two', 'Three']
    ...     table = [['test1', 2, 3.0],
    ...             ['test4', 5, 6.0],
    ...             ['test7', 8, 9.0],
    ...             ]
    ...     print ''.join(column.rjust(10) for column in headers)
    ...     for row in table:
    ...         print ''.join(str(column).rjust(10) for column in row)
    ... 
    >>> 
    >>> print_table()
           One       Two     Three
         test1         2       3.0
         test4         5       6.0
         test7         8       9.0
    >>> 
    

    No need for the string module or integers to index into the table.

    I’ve printed to standard out for clarity, but you can write to a file just as easily.

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

Sidebar

Related Questions

I have a text file from which I want to create a Hash for
I want to create an xml file which have '&' in one of its
I have a text file which was created using some Microsoft reporting tool. The
I want to be able to create a temporary text File in Java to
I want to pre-append some text a a CSV file that is created by
I want to create a form which has a text entry box where a
I want to create a dialog that contains some kind of text element (JLabel/JTextArea
I want to create a plugin 'myPlugin' which simply add some text to a
this table i want to create job_id dynamic Jobs Title text Job Description text
Let's say I wanted to create a static text file which ships with each

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.