Evaluate infix math expresion in python with ease.
Project description
Py-MathParser
Py-MathParser is a Python binding for MathParser (https://github.com/KJ002/MathParser/). This module allows for a simple and quick evaluation of strings. It allows you to evaluate a string with security, you define the external variables!
Examples
Basic Eval
result: float = MathParser.evaluate("1+1") # returns 2
Basic Eval (With MathParser Class)
parser = MathParser.Parser()
rpn: MathParser.mp_RPN = parser.reverse_polish_notation("1+1")
result: float = parser.eval(rpn) # returns 2
External Variable Eval
parser = MathParser.Parser()
x: int = 20
parser.append_variable("x", x)
rpn: MathParser.mp_RPN = parser.reverse_polish_notation("1+x")
result: float = parser.eval(rpn) # returns 21
Updating External Variable Eval
parser = MathParser.Parser()
x: int = 20
parser.append_variable("x", x)
rpn: MathParser.mp_RPN = parser.reverse_polish_notation("1+x")
result1: float = parser.eval(rpn) # returns 21
x: int = 10
parser.append_variable("x", x)
result2: float = parser.eval(rpn) # returns 11
Functions Eval
parser = MathParser.Parser()
rpn: MathParser.mp_RPN = parser.reverse_polish_notation("sin(1.5707963267948966)")
result: float = parser.eval(rpn) # returns 1
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
InfixParser-0.1.7.tar.gz
(5.3 kB
view hashes)
Built Distribution
Close
Hashes for InfixParser-0.1.7-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c5ebe2f484e88271c90448cb6d0d83c2b4c276b450faa3af628d578cf1c9ff5 |
|
MD5 | 511d4d6d6162e7b6e3397005a68f7392 |
|
BLAKE2b-256 | d01886c1da00122b3ad074652b83234c8545272e46d8b60a276f98c4d590711b |