Skip to main content

+/- plusminus is a module that builds on the pyparsing infixNotation helper method to build easy-to-code and easy-to-use parsers for parsing and evaluating infix arithmetic expressions. plusminus's ArithmeticParser class includes separate parse and evaluate methods, handling operator precedence, override with parentheses, presence or absence of whitespace, built-in functions, and pre-defined and user-defined variables, functions, and operators.

Project description

plusminus

The plusminus package provides a ready-to-run arithmetic parser and evaluator, based on pyparsing's infixNotation helper method.

Strings containing 5-function arithmetic expressions can be parsed and evaluated using the BasicArithmeticParser:

from plusminus import BasicArithmeticParser

parser = BasicArithmeticParser()
print(parser.evaluate("2+3/10"))

The parser can also return an Abstract Syntax Tree of ArithNode objects:

parsed_elements = parser.parse("2+3/10")

Arithmetic expressions are evaluated following standard rules for operator precedence, allowing for use of parentheses ()'s to override:

()
-
**
* / × ÷ mod
+ -
< > <= >= == != ≠ ≤ ≥
between-and within-and "in range from"-to (ternary) (between is exclusive, within is inclusive, and `in range from` is
  inclusive lower-bound and exclusive upper-bound)
not
and ∧
or ∨
? : (ternary)

Functions can be called:

  sin   sinh  abs    log2   rnd
  cos   cosh  round  log10  randint
  tan   tanh  trunc  gcd    min
  asin  rad   ceil   lcm    max
  acos  deg   floor  gamma
  atan  sgn   ln     hypot

The Basic ArithmeticParser also supports assignment of variables:

r = 5
area = π × r²

This last expression could be assigned using '@=' formula assignment:

area @= π × r²

As r is updated, evaluating area will be reevaluated using the new value.

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

plusminus-0.1.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

plusminus-0.1-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file plusminus-0.1.tar.gz.

File metadata

  • Download URL: plusminus-0.1.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.8.0

File hashes

Hashes for plusminus-0.1.tar.gz
Algorithm Hash digest
SHA256 1d7ab8e2a7f809931e591650922870bd69061dde56d6a9668f0518ac76adc949
MD5 d325eea483ac3f18e13ddf974de84d57
BLAKE2b-256 d1d135eb3298657c7d6f087d05c9b57fb7a2d8fbf644e3bcc0c3ff0f3dc9a30a

See more details on using hashes here.

File details

Details for the file plusminus-0.1-py3-none-any.whl.

File metadata

  • Download URL: plusminus-0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.8.0

File hashes

Hashes for plusminus-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1290ecf09a51847393ba89f55e430a69962df68a590a1ab6ec7eff973d164967
MD5 1bb94e3850c7def91d437d10ac50d8b4
BLAKE2b-256 4b593ccabb34211837bbb58b514d10bfb06126ba4c747c9e0ae5a8ef19ba7522

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page