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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:46:07+00:00 2026-05-27T08:46:07+00:00

Using python2.7, I’m trying to print to screen tabular data. This is roughly what

  • 0

Using python2.7, I’m trying to print to screen tabular data.

This is roughly what my code looks like:

for i in mylist:
   print "{}\t|{}\t|".format (i, f(i))

The problem is that, depending on the length of i or f(i) the data won’t be aligned.

This is what I’m getting:

|foo |bar |
|foobo   |foobar  |

What I want to get:

|foo     |bar     |
|foobo   |foobar  |

Are there any modules that permit doing this?

  • 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-27T08:46:07+00:00Added an answer on May 27, 2026 at 8:46 am

    It’s not really hard to roll your own formatting function:

    def print_table(table):
        col_width = [max(len(x) for x in col) for col in zip(*table)]
        for line in table:
            print "| " + " | ".join("{:{}}".format(x, col_width[i])
                                    for i, x in enumerate(line)) + " |"
    
    table = [(str(x), str(f(x))) for x in mylist]
    print_table(table)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using httplib2 and urllib2, I'm trying to fetch pages from this url, but all
I'm trying to delete a user using Django Admin, but I get this error:
I'm trying to install pyobjc (using pyobjc-1.2-python2.3-macosx10.2.dmg) on a Mac running OSX 10.6 and
Using Python2.4 I want to capture output from a mysql command. One caveat is
How can use Python2.5 with to write scripts in vim? I'm using vim 7.2
Using Python's Imaging Library I want to create a PNG file. I would like
I am working with python plugins for qgis.I am using python2.5 and pyqt4 designer.I
I am working with python plugins for QGIS.I am using python2.5 and pyqt4 .My
I'm setting up a virtualenv , but it seems to be using python2.5 by
I'm trying to compile pymssql for python 2.5. I'm doing this because I think

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.