[Python-modules-commits] r8579 - in packages/prettytable/trunk/debian (prettytable-example.py)
morph at users.alioth.debian.org
morph at users.alioth.debian.org
Wed May 27 07:14:01 UTC 2009
Date: Wednesday, May 27, 2009 @ 07:14:00
Author: morph
Revision: 8579
fixed example
Modified:
packages/prettytable/trunk/debian/prettytable-example.py
Modified: packages/prettytable/trunk/debian/prettytable-example.py
===================================================================
--- packages/prettytable/trunk/debian/prettytable-example.py 2009-05-27 06:56:11 UTC (rev 8578)
+++ packages/prettytable/trunk/debian/prettytable-example.py 2009-05-27 07:14:00 UTC (rev 8579)
@@ -1,6 +1,8 @@
#!/usr/bin/python
# Example extracted from the source code of prettytable module
+from prettytable import PrettyTable
+
def main():
x = PrettyTable(["City name", "Area", "Population", "Annual Rainfall"])
@@ -14,66 +16,6 @@
x.add_row(["Perth", 5386, 1554769, 869.4])
print x
- if len(sys.argv) > 1 and sys.argv[1] == "test":
-
- # This "test suite" is hideous and provides poor, arbitrary coverage.
- # I'll replace it with some proper unit tests Sometime Soon (TM).
- # Promise.
- print "Testing field subset selection:"
- x.printt(fields=["City name","Population"])
- print "Testing row subset selection:"
- x.printt(start=2, end=5)
- print "Testing hrules settings:"
- print "FRAME:"
- x.printt(hrules=FRAME)
- print "ALL:"
- x.printt(hrules=ALL)
- print "NONE:"
- x.printt(hrules=NONE)
- print "Testing lack of headers:"
- x.printt(header=False)
- x.printt(header=False, border=False)
- print "Testing lack of borders:"
- x.printt(border=False)
- print "Testing sorting:"
- x.printt(sortby="City name")
- x.printt(sortby="Annual Rainfall")
- x.printt(sortby="Annual Rainfall", reversesort=True)
- print "Testing padding parameter:"
- x.set_padding_width(0)
- x.printt()
- x.set_padding_width(5)
- x.printt()
- x.set_left_padding(5)
- x.set_right_padding(0)
- x.printt()
- x.set_right_padding(20)
- x.printt()
- x.set_left_padding(None)
- x.set_right_padding(None)
- x.set_padding_width(2)
- print "Testing changing characters"
- x.set_border_chars("*","*","*")
- x.printt()
- x.set_border_chars("!","~","o")
- x.printt()
- x.set_border_chars("|","-","+")
- print "Testing everything at once:"
- x.printt(start=2, end=5, fields=["City name","Population"], border=False, hrules=True)
- print "Rebuilding by columns:"
- x = PrettyTable()
- x.add_column("City name", ["Adelaide", "Brisbane", "Darwin", "Hobart", "Sydney", "Melbourne", "Perth"])
- x.add_column("Area", [1295, 5905, 112, 1357, 2058, 1566, 5385])
- x.add_column("Population", [1158259, 1857594, 120900, 205556, 4336374, 3806092, 1554769])
- x.add_column("Annual Rainfall", [600.5, 1146.4, 1714.7, 619.5, 1214.8, 646.9, 869.4])
- x.printt()
- print "Testing HTML:"
- x.print_html()
- x.print_html(border=False)
- x.print_html(border=True)
- x.print_html(format=False)
- x.print_html(attributes={"name": "table", "id": "table"})
-
if __name__ == "__main__":
main()
More information about the Python-modules-commits
mailing list