#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    17
    Rep Power
    0

    Question Printing Table Data


    Hello,

    I always find myself printing data in tables. Does anyone know of a cool script that I can use that would automatically print out the data in a table in a formatted way, html-zied or not? Thanks!
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    10
    Rep Power
    0
    table = get_table()

    print '<html><body><table>'
    for r in table:
    print '<tr>'
    for c in r:
    print '<td>'
    print c
    print '</td>'
    print '</tr>'
    print '</table></body></html>
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Please use code tags in future, also, read the sticky regarding how to post!

    Code:
    table = ((1, 2, 3), (4, 5, 6))
    
    print '<table>'
    for row in table:
        print '    <tr>'
        for col in row: print '        <td>%s</td>' % col
        print '    </tr>'
    print '</table>'
    This will work fine - the spaces here are simply to indent the HTML for easy reading, if that doesnt matter to you just remove any white space at the beginning of the print statments.

    Remember, you'll have to make sure that each row contains the same number of columns or you're table will break!

    Mark.
    programming language development: www.netytan.com Hula

  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    17
    Rep Power
    0
    Thanks for the reply guys! I will try them out as soon as I can.

IMN logo majestic logo threadwatch logo seochat tools logo