Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 12th, 2004, 02:44 PM
zci zci is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 17 zci User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 31 sec
Reputation 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!

Reply With Quote
  #2  
Old July 14th, 2004, 04:40 AM
gen_rec gen_rec is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 10 gen_rec User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 48 sec
Reputation 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>

Reply With Quote
  #3  
Old July 14th, 2004, 05:59 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 3 m 4 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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


Reply With Quote
  #4  
Old July 22nd, 2004, 06:46 PM
zci zci is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 17 zci User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 31 sec
Reputation Power: 0
Thanks for the reply guys! I will try them out as soon as I can.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Printing Table Data


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT