convert a logical expression written in `Python` syntax, into a `Sympy` expression
Project description
logic_python2sympy
Sympy
has the advantage of using Python
syntax in its own expressions, but with some exceptions :
logical expressions in Sympy
differ a bit from their Python
counterparts (a and b
is written a & b
in Sympy
).
Thus, this module provides functions that can convert a logical expression written in Python
syntax, into a Sympy
expression.
Usage
>>> import logic_python2sympy as p2s
>>> code = "((0 < x <= 10) or not y"
>>> print(p2s.convert(code))
Or(And(0 < x, x <= 10), Not(y))
>> print(p2s.get_expression(code))
~y | ((0 < x) & (x <= 10))
convert
convert(expr: str) -> str
Transform a Python
logical expression into Sympy
syntax.
expr: valid logical expression, i.e. expr must be valid Python
syntax, and must be a combintion of the following ast
nodes: BoolOp, BinOp, UnaryOp, Compare, Call, Constant, Name
raises: NotImplentedError
, when the expression contains operators that are not supported in Sympy
get_expression
get_expression(expr: str) -> Any
Transform a Python
logical expression into a Sympy
expression.
expr: valid logical expression, i.e. expr must be valid Python
syntax,
and must be a combintion of the following ast
nodes:
BoolOp, BinOp, UnaryOp, Compare, Call, Constant, Name
raises: NotImplentedError
, when the expression contains operators that are not supported in Sympy
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for logic_python2sympy-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3aa1d80efaf7c2af884aedf1555a4e31bd5e546d47124c2d2e006ca768ba2172 |
|
MD5 | 62f6fe762c159c6ec69f656cf0fcab6d |
|
BLAKE2b-256 | 86334a0bd161687e118b0e6c9784fe5cb3cb5efbe31aef4c96a4d42d801b5a9c |