6 Years
Discussion Span
Last Post by felix001

If you want small self contained one, most simplest white space only version has been last in DaniWeb in my post: http://www.daniweb.com/software-development/python/threads/385547/1661150#post1661150

That case was simpler in that way that last number of range is known to be (one of the) longest, normally you would need to use max funcition on value strings.

However it is good idea to use the previously tested general modules mentioned (and in his part developed) by Gribouillis. Actually I have made similar post in StackOverflow about same topic, but Gribouillis method here is nicer than method there: http://stackoverflow.com/questions/3319540/how-to-extend-pretty-print-module-to-tables

I posted a link to module (maybe mentioned also by Gribouillis) those times:
http://code.google.com/p/prettytable/ as solution to the problem (can be installed as with pip also). Actually I have not used that module as the question was more out of curiousity for me.

Also it is not so difficult to build html for table to be shown in web browser. Web browser does all job of formatting and makes the table even resizable.

## http://code.google.com/p/prettytable/wiki/Tutorial
from prettytable import PrettyTable
import webbrowser

x = PrettyTable(["City name", "Area", "Population", "Annual Rainfall"])
x.set_field_align("City name", "l") # Left align city names
x.set_padding_width(1) # One space between column edges and contents (default)
x.add_row(["Adelaide",1295, 1158259, 600.5])
x.add_row(["Brisbane",5905, 1857594, 1146.4])
x.add_row(["Darwin", 112, 120900, 1714.7])
x.add_row(["Hobart", 1357, 205556, 619.5])
x.add_row(["Sydney", 2058, 4336374, 1214.8])
x.add_row(["Melbourne", 1566, 3806092, 646.9])
x.add_row(["Perth", 5386, 1554769, 869.4])

with open('test.html', 'w') as testfile:

Edited by pyTony: n/a

Votes + Comments
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.