Embedded text tables in Python code
Python
Latest commit 20a60d5 Feb 24, 2017 @fjkz Remove Table.__init__
As I do not want to show Table.__init__ to users,
I rename it to Table._initialize.

README.rst

inline_table - Embedded text tables in Python code

inline_table is a Python module for embedding text tables into source-code.

Table is a good notation. It is simple and easy to read. We can see if we concern about all cases MECE-ly or not. We create many tables as software design works: decision tables, state transition tables, etc.

We cannot, however, write tables directly with programming languages. We convert tables to source-code with if-statements manually. Manual operations usually cause mistakes. And today readability of source-code becomes important. When we read source-code, we must reconstruct design tables from source-code. This work is ineffective.

We need a way to write tables in source-code. We should be able to write code as a document. The inline_table module enables us to do it.

Write a simple logic more simply.

Example

inline_table compiles a text table to a Table object. We can query a row in the table. The follow is an example:

>>> import inline_table
>>> text = '''
... ============ ======== ==========
... age (cond)   gender   call (str)
... ============ ======== ==========
...  0 <= a < 2   *       baby
...  0 <= a < 7   *       kid
...  7 <= a < 18  M       boy
...  7 <= a < 16  F       girl
... 18 <= a       M       gentleman
... 16 <= a       F       lady
...       *       *       man
... ============ ======== ==========
... '''
>>> table = inline_table.compile(text, M='male', F='female')
>>> table.select(age=24, gender='female')
Tuple(age=24, gender='female', call='lady')

See the API document for the detail of the usage.

Installation

We can install the package with the following command:

$ python setup.py install

Testing

We can run unit-tests with the following command:

$ python setup.py test

Requirements

  • Python 2.6, 2.7, 3.2 or later
  • docutils package 0.13 or later

License

This work is released under the MIT License, see LICENSE.txt for details.