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

  • Home
  • SEARCH
  • 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 1081601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:11:22+00:00 2026-05-16T22:11:22+00:00

I have a list of labels, and data as follows. [‘id’, ‘Version’, ‘chip_name’, ‘xversion’,

  • 0

I have a list of labels, and data as follows.

['id', 'Version', 'chip_name', 'xversion', 'device', 'opt_param', 'place_effort']
[1, 1.0, u'virtex2', u'xilinx11.5', u'xc5vlx50', u'Speed', u'High']

I need to print them into console. And for this, I’m iterating over the list, and print out each element with a tab (‘\t’).

But, unfortunately, the result is not so pretty.


number of data 1 and number of column 7
id      Version     chip_name       xversion        device      opt_param       place_effort        
1       1.0     virtex2     xilinx11.5      xc5vlx50        Speed       High        

The string length of label and data is quite variable, and it’s not aligned well.

Is there any solution to this problem with Python?

ADDED

Hepled by Mike DeSimone’s answer, I could make the pretty printer that I can use for my purposes. The valueResults are a list of duple.

    labels = queryResult.names
    valueResults = queryResult.result

    # get the maximum width
    allData = valueResults
    allData.insert(0,labels)
    transpose = zip(*valueResults) # remove the sequence as a parameter
    #print transpose
    for value in transpose:
        # value is integer/float/unicode/str, so make it length of str
        newValue = [len(str(i)) for i in value]
        columnWidth = max(newValue)
        columnWidths.append(columnWidth)
        dividers.append('-' * columnWidth)
        dblDividers.append('=' * columnWidth)
        label = value[0]
        paddedLabels.append(label.center(columnWidth))

    paddedString = ""

    for values in valueResults[1:]:
        paddedValue = []
        for i, value in enumerate(values):
            svalue = str(value)
            columnWidth = columnWidths[i]
            paddedValue.append(svalue.center(columnWidth))
        paddedString += '| ' + ' | '.join(paddedValue) + ' |' + '\n'

    string += '+-' + '-+-'.join(dividers) + '-+' + '\n'
    string += '| ' + ' | '.join(paddedLabels) + ' |' + '\n'
    string += '+=' + '=+='.join(dblDividers) + '=+' + '\n'
    string += paddedString
    string += '+-' + '-+-'.join(dividers) + '-+' + '\n'

And this is the result.


+----+---------+-----------+------------+----------+-----------+--------------+
| id | Version | chip_name |  xversion  |  device  | opt_param | place_effort |
+====+=========+===========+============+==========+===========+==============+
| 1  |   1.0   |  virtex2  | xilinx11.5 | xc5vlx50 |   Speed   |     High     |
| 2  |   1.0   |  virtex2  | xilinx11.5 | xc5vlx50 |   Speed   |     High     |
+----+---------+-----------+------------+----------+-----------+--------------+

Thanks for the help.

  • 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-16T22:11:23+00:00Added an answer on May 16, 2026 at 10:11 pm

    Something like this:

    labels = ['id', 'Version', 'chip_name', 'xversion', 'device', 'opt_param', 
        'place_effort']
    values = [1, 1.0, u'virtex2', u'xilinx11.5', u'xc5vlx50', u'Speed', u'High']
    
    paddedLabels = []
    paddedValues = []
    
    for label, value in zip(labels, values):
        value = str(value)
        columnWidth = max(len(label), len(value))
        paddedLabels.append(label.center(columnWidth))
        paddedValues.append(value.center(columnWidth))
    
    print ' '.join(paddedLabels)
    print ' '.join(paddedValues)
    

    Output:

    id Version chip_name  xversion   device  opt_param place_effort
    1    1.0    virtex2  xilinx11.5 xc5vlx50   Speed       High
    

    If you want to get fancy, make it reStructuredText-ready:

    labels = ['id', 'Version', 'chip_name', 'xversion', 'device', 'opt_param', 
        'place_effort']
    values = [1, 1.0, u'virtex2', u'xilinx11.5', u'xc5vlx50', u'Speed', u'High']
    
    paddedLabels = []
    paddedValues = []
    dividers = []
    dblDividers = []
    
    for label, value in zip(labels, values):
        value = str(value)
        columnWidth = max(len(label), len(value))
        paddedLabels.append(label.center(columnWidth))
        paddedValues.append(value.center(columnWidth))
        dividers.append('-' * columnWidth)
        dblDividers.append('=' * columnWidth)
    
    print '+-' + '-+-'.join(dividers) + '-+'
    print '| ' + ' | '.join(paddedLabels) + ' |'
    print '+=' + '=+='.join(dblDividers) + '=+'
    print '| ' + ' | '.join(paddedValues) + ' |'
    print '+-' + '-+-'.join(dividers) + '-+'
    

    Output:

    +----+---------+-----------+------------+----------+-----------+--------------+
    | id | Version | chip_name |  xversion  |  device  | opt_param | place_effort |
    +====+=========+===========+============+==========+===========+==============+
    | 1  |   1.0   |  virtex2  | xilinx11.5 | xc5vlx50 |   Speed   |     High     |
    +----+---------+-----------+------------+----------+-----------+--------------+
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to generate labels from a list of user data stored in a
I have a list of textboxes with corresponding labels. When the user inputs a
I have this long list of checkboxes with specific labels that look something like
I have this long list of checkboxes with specific labels that look something like
I have a radio button list and some of the labels are quite long
If I have a drop down list as follows <div class=editor-label> <%= Html.DropDownListFor(model =>
I have list of structure. I want to modify a particular data from the
I have a repeater which fetches data from a database and shows some labels
I have a data frame in R defined as follows: data frame: col 1
I have three methods. The first method takes data from a List (which contains

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.