This module provides a number of functions which come in handy when programming web applications but that don't fit in elsewhere. It is a catch all module for useful leftovers.
text, width) |
html, [validTags=[]]) |
[root='../', cgi='/cgi-bin', ]) |
Warning: NOT SUITABLE FOR COMMERCIAL USE.
/
values, [width=80]) |
( (column1Heading, (column1value1, column1value2, column1value3)), (column2Heading, (column2value1, column2value2, column2value3)), (column3Heading, (column3value1, column3value2, column3value3)), )
str()
.
80
which means the table will we wrapped to the width of a standard terminla or command line prompt. If width is set to 0
no wrapping is produced.
For example:
#!/usr/bin/env python import sys; sys.path.append('../../../') # show python where the web modules are import web.util table = ( ('column1Heading', ('column1value1', 'column1value2', 'column1value3')), ('column2Heading', ('column2value1', 'column2value2', 'column2value3')), ('column3Heading', ('column3value1', 'column3value2', 'column3value3')), ('column4Heading', ('column4value1', 'column4value2', 'column4value3')), ) print "Printing the table with wrap width=0...\n" print web.util.table(table, width=0) print "Printing the table with wrap width=60...\n" print web.util.table(table, width=60)
The output produced is: Printing the table with wrap width=0... +----------------+----------------+----------------+----------------+ | column4Heading | column3Heading | column2Heading | column1Heading | +----------------+----------------+----------------+----------------+ | column4value1 | column3value1 | column2value1 | column1value1 | | column4value2 | column3value2 | column2value2 | column1value2 | | column4value3 | column3value3 | column2value3 | column1value3 | +----------------+----------------+----------------+----------------+ Printing the table with wrap width=60... +----------------+----------------+----------------+-------- | column4Heading | column3Heading | column2Heading | column1 +----------------+----------------+----------------+-------- | column4value1 | column3value1 | column2value1 | column1 | column4value2 | column3value2 | column2value2 | column1 | column4value3 | column3value3 | column2value3 | column1 +----------------+----------------+----------------+-------- --------+ Heading | --------+ value1 | value2 | value3 | --------+
Warning: If you don't set the wrap width and your table is wider than the terminal then the terminal will wrap the table output itself. If this happens it will wrap each induvidual line of text rather than the whole table producing output that looks more like this:
+----------------+----------------+-------------- --+----------------+ | column4Heading | column3Heading | column2Headin g | column1Heading | +----------------+----------------+-------------- --+----------------+ | column4value1 | column3value1 | column2value1 | column1value1 | | column4value2 | column3value2 | column2value2 | column1value2 | | column4value3 | column3value3 | column2value3 | column1value3 | +----------------+----------------+-------------- --+----------------+
See About this document... for information on suggesting changes.