diff --git a/PKG-INFO b/PKG-INFO index 557319d..6eab838 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,12 +1,12 @@ Metadata-Version: 1.0 Name: texttable -Version: 0.8.5 +Version: 0.8.6 Summary: module for creating simple ASCII tables Home-page: https://github.com/foutaise/texttable/ Author: Gerome Fournier Author-email: jef(at)foutaise.org License: LGPL -Download-URL: https://github.com/foutaise/texttable/archive/v0.8.5.tar.gz +Download-URL: https://github.com/foutaise/texttable/archive/v0.8.6.tar.gz Description: texttable is a module to generate a formatted text table, using ASCII characters. Platform: any diff --git a/README.md b/README.md index 07a8cc6..a54db32 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Python module for creating simple ASCII tables ## Availability -This module is available on [PypI](https://pypi.python.org/pypi/texttable/0.8.5), and has been packaged for several Linux/Unix platforms +This module is available on [PypI](https://pypi.python.org/pypi/texttable/0.8.6), and has been packaged for several Linux/Unix platforms ([Debian](https://packages.debian.org/search?&searchon=names&keywords=python-texttable+), [FreeBSD](https://www.freebsd.org/cgi/ports.cgi?query=texttable&stype=all), Fedora, Suse...). @@ -15,23 +15,24 @@ NAME texttable - module for creating simple ASCII tables FILE - /usr/lib/python2.3/site-packages/texttable.py + /usr/local/lib/python2.7/dist-packages/texttable.py DESCRIPTION - + Example: - + table = Texttable() table.set_cols_align(["l", "r", "c"]) table.set_cols_valign(["t", "m", "b"]) - table.add_rows([["Name", "Age", "Nickname"], + table.add_rows([["Name", "Age", "Nickname"], ["Mr\nXavier\nHuon", 32, "Xav'"], - ["Mr\nBaptiste\nClement", 1, "Baby"]]) + ["Mr\nBaptiste\nClement", 1, "Baby"], + ["Mme\nLouise\nBourgeau", 28, "Lou\n\nLoue"]]) print table.draw() + "\n" - + table = Texttable() table.set_deco(Texttable.HEADER) - table.set_cols_dtype(['t', # text + table.set_cols_dtype(['t', # text 'f', # float (decimal) 'e', # float (exponent) 'i', # integer @@ -43,9 +44,9 @@ DESCRIPTION ["lmn", 5e-78, 5e-78, 89.4, .000000000000128], ["opqrstu", .023, 5e+78, 92., 12800000000000000000000]]) print table.draw() - + Result: - + +----------+-----+----------+ | Name | Age | Nickname | +==========+=====+==========+ @@ -57,7 +58,11 @@ DESCRIPTION | Baptiste | 1 | | | Clement | | Baby | +----------+-----+----------+ - + | Mme | | Lou | + | Louise | 28 | | + | Bourgeau | | Loue | + +----------+-----+----------+ + text float exp int auto =========================================== abcd 67.000 6.540e+02 89 128.001 @@ -68,132 +73,132 @@ DESCRIPTION CLASSES class Texttable | Methods defined here: - | + | | __init__(self, max_width=80) | Constructor - | + | | - max_width is an integer, specifying the maximum width of the table | - if set to 0, size is unlimited, therefore cells won't be wrapped - | + | | add_row(self, array) | Add a row in the rows stack - | + | | - cells can contain newlines and tabs - | + | | add_rows(self, rows, header=True) | Add several rows in the rows stack - | + | | - The 'rows' argument can be either an iterator returning arrays, | or a by-dimensional array | - 'header' specifies if the first row should be used as the header | of the table - | + | | draw(self) | Draw the table - | + | | - the table is returned as a whole string - | + | | header(self, array) | Specify the header of the table - | + | | reset(self) | Reset the instance - | + | | - reset rows and header - | + | | set_chars(self, array) | Set the characters used to draw lines between rows and columns - | + | | - the array should contain 4 fields: - | + | | [horizontal, vertical, corner, header] - | + | | - default is set to: - | + | | ['-', '|', '+', '='] - | + | | set_cols_align(self, array) | Set the desired columns alignment - | + | | - the elements of the array should be either "l", "c" or "r": - | + | | * "l": column flushed left | * "c": column centered | * "r": column flushed right - | + | | set_cols_dtype(self, array) | Set the desired columns datatype for the cols. - | + | | - the elements of the array should be either "a", "t", "f", "e" or "i": - | + | | * "a": automatic (try to use the most appropriate datatype) | * "t": treat as text | * "f": treat as float in decimal format | * "e": treat as float in exponential format | * "i": treat as int - | + | | - by default, automatic datatyping is used for each column - | + | | set_cols_valign(self, array) | Set the desired columns vertical alignment - | + | | - the elements of the array should be either "t", "m" or "b": - | + | | * "t": column aligned on the top of the cell | * "m": column aligned on the middle of the cell | * "b": column aligned on the bottom of the cell - | + | | set_cols_width(self, array) | Set the desired columns width - | + | | - the elements of the array should be integers, specifying the | width of each column. For example: - | + | | [10, 20, 5] - | + | | set_deco(self, deco) | Set the table decoration - | + | | - 'deco' can be a combinaison of: - | + | | Texttable.BORDER: Border around the table | Texttable.HEADER: Horizontal line below the header | Texttable.HLINES: Horizontal lines between rows | Texttable.VLINES: Vertical lines between columns - | + | | All of them are enabled by default - | + | | - example: - | + | | Texttable.BORDER | Texttable.HEADER - | + | | set_precision(self, width) | Set the desired precision for float/exponential formats - | + | | - width must be an integer >= 0 - | + | | - default value is set to 3 - | + | | ---------------------------------------------------------------------- | Data and other attributes defined here: - | + | | BORDER = 1 - | + | | HEADER = 2 - | + | | HLINES = 4 - | + | | VLINES = 8 DATA __all__ = ['Texttable', 'ArraySizeError'] __author__ = 'Gerome Fournier ' - __credits__ = 'Jeff Kowalczyk:\n - textwrap improved import\n ...:\... + __credits__ = 'Jeff Kowalczyk:\n - textwrap improved import\n ...at... __license__ = 'LGPL' - __version__ = '0.8.5' + __version__ = '0.8.6' VERSION - 0.8.5 + 0.8.6 AUTHOR Gerome Fournier @@ -202,22 +207,25 @@ CREDITS Jeff Kowalczyk: - textwrap improved import - comment concerning header output - + Anonymous: - add_rows method, for adding rows in one go - + Sergey Simonenko: - redefined len() function to deal with non-ASCII characters - + Roger Lew: - columns datatype specifications - + Brian Peterson: - better handling of unicode errors - + Frank Sachsenheim: - add Python 2/3-compatibility - + Maximilian Hils: - fix minor bug for Python 3 compatibility + + frinkelpi + - preserve empty lines ``` diff --git a/setup.py b/setup.py index b5ed3ff..9aa5aed 100644 --- a/setup.py +++ b/setup.py @@ -33,11 +33,11 @@ setup( name = "texttable", - version = "0.8.5", + version = "0.8.6", author = "Gerome Fournier", author_email = "jef(at)foutaise.org", url = "https://github.com/foutaise/texttable/", - download_url = "https://github.com/foutaise/texttable/archive/v0.8.5.tar.gz", + download_url = "https://github.com/foutaise/texttable/archive/v0.8.6.tar.gz", license = "LGPL", py_modules = ["texttable"], description = DESCRIPTION, diff --git a/texttable.py b/texttable.py index d6fdae5..9547cbe 100644 --- a/texttable.py +++ b/texttable.py @@ -27,7 +27,8 @@ table.set_cols_valign(["t", "m", "b"]) table.add_rows([["Name", "Age", "Nickname"], ["Mr\\nXavier\\nHuon", 32, "Xav'"], - ["Mr\\nBaptiste\\nClement", 1, "Baby"]]) + ["Mr\\nBaptiste\\nClement", 1, "Baby"], + ["Mme\\nLouise\\nBourgeau", 28, "Lou\\n\\nLoue"]]) print table.draw() + "\\n" table = Texttable() @@ -58,6 +59,10 @@ | Baptiste | 1 | | | Clement | | Baby | +----------+-----+----------+ + | Mme | | Lou | + | Louise | 28 | | + | Bourgeau | | Loue | + +----------+-----+----------+ text float exp int auto =========================================== @@ -71,7 +76,7 @@ __author__ = 'Gerome Fournier ' __license__ = 'LGPL' -__version__ = '0.8.4' +__version__ = '0.8.6' __credits__ = """\ Jeff Kowalczyk: - textwrap improved import @@ -94,6 +99,9 @@ Maximilian Hils: - fix minor bug for Python 3 compatibility + +frinkelpi + - preserve empty lines """ import sys @@ -572,7 +580,10 @@ def _splitit(self, line, isheader): for cell, width in zip(line, self._width): array = [] for c in cell.split('\n'): - array.extend(textwrap.wrap(c, width)) + if c.strip() == "": + array.append("") + else: + array.extend(textwrap.wrap(c, width)) line_wrapped.append(array) max_cell_lines = reduce(max, list(map(len, line_wrapped))) for cell, valign in zip(line_wrapped, self._valign): @@ -595,7 +606,8 @@ def _splitit(self, line, isheader): table.set_cols_valign(["t", "m", "b"]) table.add_rows([["Name", "Age", "Nickname"], ["Mr\nXavier\nHuon", 32, "Xav'"], - ["Mr\nBaptiste\nClement", 1, "Baby"]]) + ["Mr\nBaptiste\nClement", 1, "Baby"], + ["Mme\nLouise\nBourgeau", 28, "Lou\n \nLoue"]]) print(table.draw() + "\n") table = Texttable()