Skip to main content

Synopsis

tt is a Python library and command-line tool for working with Boolean expressions. Please check out the project site for more information.

Installation

tt is tested on CPython 2.7, 3.3, 3.4, 3.5, and 3.6 as well as PyPy. tt is written in pure Python with no dependencies, so it only requires a compatible Python installation to run. You can get the latest release from PyPI with:

pip install ttable

Basic Usage

Below are a couple of examples to show you the kind of things tt can do. For more examples and further documentation, take a look at the project site.

As a Library

tt aims to provide a Pythonic interface for working with Boolean expressions. Here are some simple examples from the REPL:

>>> from tt import BooleanExpression, TruthTable
>>> b = BooleanExpression('A xor (B and 1)')
>>> b.tokens
['A', 'xor', '(', 'B', 'and', '1', ')']
>>> b.symbols
['A', 'B']
>>> print(b.tree)
xor
`----A
`----and
     `----B
     `----1
>>> b.evaluate(A=True, B=False)
True
>>> t = TruthTable(b)
>>> print(t)
+---+---+---+
| A | B |   |
+---+---+---+
| 0 | 0 | 0 |
+---+---+---+
| 0 | 1 | 1 |
+---+---+---+
| 1 | 0 | 1 |
+---+---+---+
| 1 | 1 | 0 |
+---+---+---+
>>> t = TruthTable('A or B', fill_all=False)
>>> print(t)
Empty!
>>> t.fill(A=0)
>>> print(t)
+---+---+---+
| A | B |   |
+---+---+---+
| 0 | 0 | 0 |
+---+---+---+
| 0 | 1 | 1 |
+---+---+---+
>>> t.fill(A=1)
>>> print(t)
+---+---+---+
| A | B |   |
+---+---+---+
| 0 | 0 | 0 |
+---+---+---+
| 0 | 1 | 1 |
+---+---+---+
| 1 | 0 | 1 |
+---+---+---+
| 1 | 1 | 1 |
+---+---+---+

From the Command Line

tt also provides a command-line interface for working with expressions. Here are a couple of examples:

$ tt tokens "(op1 nand op2) xnor op3"
(
op1
nand
op2
)
xnor
op3

$ tt table A or B
+---+---+---+
| A | B |   |
+---+---+---+
| 0 | 0 | 0 |
+---+---+---+
| 0 | 1 | 1 |
+---+---+---+
| 1 | 0 | 1 |
+---+---+---+
| 1 | 1 | 1 |
+---+---+---+

$ tt tree A or or B
Error! Unexpected binary operator "or":
A or or B
     ^

License

tt uses the MIT License.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ttable-0.5.0.tar.gz (571.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ttable-0.5.0-py2.py3-none-any.whl (21.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file ttable-0.5.0.tar.gz.

File metadata

  • Download URL: ttable-0.5.0.tar.gz
  • Upload date:
  • Size: 571.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ttable-0.5.0.tar.gz
Algorithm Hash digest
SHA256 823515844867a2e4cbbbc5cdb49dfceb41087aff56cd12a4fd70aa7e0a5eb4be
MD5 aae7278d12e598f8383c258f0a929a44
BLAKE2b-256 c71210af527675d5d70f98d0397a2b6385dfe8a9fda21e72810be54c6c6525b7

See more details on using hashes here.

File details

Details for the file ttable-0.5.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for ttable-0.5.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1796e7f180e5298f9cebb33a8844a388dd22eb02f608e24c4ad5d0fdbe02b208
MD5 6909a9cc2f78930ab2879778783d935e
BLAKE2b-256 cd6ee80ac09fc109bd813c26753cecbe7bf8df18997ac459683fa1dc9f71c99e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page