Skip to main content

Powerful yet easy command line calculator.

Project description

Logo

cli-calc

test codecov Python Version

pypi github release pypi downloads

Powerful yet easy command line calculator.

Introduction

python at the comand line (cli)

It is easy and common to use Python as a Calculator.

$ python
Python 3.8.5 (default, Aug  2 2020, 16:00:15)
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 2**10
1024
>>> _ / 10
102.4
>>> import math
>>> math.pi
3.141592653589793
>>> math.sin(math.pi / 2)
1.0
>>> exit()

But: There must be a better way! And there is...

cli-calc

$ cli-calc
hex, int, float,
0x0, 0, 0.0, : 2**10
2**10
0x400, 1024, 1024.0, : _ / 10
1024.0/10
0x66, 102, 102.4, : sin(pi / 2)
sin(pi/2)
0x1, 1, 1.0, : q
$

Batteries included:

  • cli-calc adds the standard math library to the mix, as well as cmath and others.

  • Provides convenience functions for formatted output, like fractions and IEEE 754.

  • Supports line input from files and unix pipes.

  • And some more... :-)

More examples

cos(pi/2)
0xFF ^ 0b10
2**8-1
log(2)
comb(49,6)
factorial(42)
random()
cmath.phase(complex(-1.0, 0.0))

Included Math Libraries

Ready to use out of the box:

Installation

pip install cli-calc

Configuration

For convenience, add a shell script in ~/bin:

cd ~/bin
vi cli-calc

with the following lines:

path=~/path/to/your/cli-calc/cli_calc
cd $path
./main.py

Make it executeable:

chmod a+x cli-calc

then use it anywhere. :-)

echo "7+8" | cli-calc
cat foo.bar | cli-calc
cli-calc

Help

calc
h
Input:
    "q" for quit, "h" for help

    "_" for last float value
    "_int_" for last int value

    "sin(pi/2)" for sinus, ...

    "pi", "tau" and "e" for pi, tau and Euler

    "+f" to add display for fraction, "-f" to suppress display for fraction
        Other letters are:
        he(x), (o)ctal, (b)inary, (i)nteger,
        (f)raction, (t)ruth, i(e)ee, ieee_bi(n), f(r)om_ieee
        "float" is always visible

    See https://docs.python.org/3/library/math.html, use without "math."
        https://www.w3schools.com/python/python_operators.asp

    Try "cos(pi/2)", XOR: "0xFF ^ 0b10", "2**8-1", "factorial(42)",
        "help(math)"

Warning

  • Use of eval is evil. However precautions are taken.

Development

Pull Request

PR's are Welcome! See PULL_REQUEST_TEMPLATE and CONTRIBUTING.

Metric Dashboard

test codecov pre-commit.ci status Documentation Status made-with-sphinx-doc

Scrutinizer Code Quality CodeQL Requirements Status Dependencies

Python Version PyPI - Implementation Python Lang Languages wemake-python-styleguide

SLOC SLOC Tests SLOC Dev code size

Maintenance MIT pypi status github stars

pypi github release pypi wheel pypi downloads

last commit GitHub commits since latest release (by SemVer) github commits since github commits rate

github issues next milestone github bugs open github bugs closed github issues open github issues closed github help open

Pull Requests open Pull Requests closed Relative date github downloads

Note on Shields

  1. Dependencies flake8-commas one of the development plugins of the wemake-python-styleguide 2 is marked as No Maintenance Intended. Hence the 1 deprecated dependency. See this Issue. Most probable wemake 2 will replace this dependency with a fork.

Features

Tools

Python Packages

Style and type annotations

  • pylint vim linter
  • isort sort imports
  • black opinionated code formatter
    • wemake strictest and most opinionated Python linter
  • mypy static type checker
  • flake8 Style Guide Enforcement
    • nitpick enforce the same settings across configuration files

Testing

Continuous Testing & Integration (CT & CI)

Integration as in: Deployment and Integration testing.

Build and publish to pypi

Following Semantic Versioning

Development Environment

  • poetry python packaging and dependency management
  • cookiecutter creates projects from project templates
  • venv creates projects from project templates

Version and Issue Management

  • git distributed version control system
  • github online collaborative version control
  • tickgit Not used, but collects TODO from source code

IDE

  • vi advanced text editor
  • VS Code source-code editor

Shell

Documentation

Metric

Jason Query for Makefile and Shields

Teaching Python Development

cli-calc Examples

NvK Tools

License

MIT

Credits

This project was generated with wemake-python-package. Current template version is: d06993f12e3ffad79652a2aec86189dee92d94dd. See what is updated since then.

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

cli-calc-0.2.22.tar.gz (19.9 kB view details)

Uploaded Source

Built Distribution

cli_calc-0.2.22-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file cli-calc-0.2.22.tar.gz.

File metadata

  • Download URL: cli-calc-0.2.22.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.8.5 Darwin/18.6.0

File hashes

Hashes for cli-calc-0.2.22.tar.gz
Algorithm Hash digest
SHA256 942c347127bfb97cf65ce185bc48d955e08a7f8e02f2c24acff4689a88e81d11
MD5 a292cdfbda0a9aee62e84c93ee01096c
BLAKE2b-256 88008d4f27c0b57adb114b1833fc2b4695340925b96dcc9bf3a768cfee2fe8e6

See more details on using hashes here.

File details

Details for the file cli_calc-0.2.22-py3-none-any.whl.

File metadata

  • Download URL: cli_calc-0.2.22-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.8.5 Darwin/18.6.0

File hashes

Hashes for cli_calc-0.2.22-py3-none-any.whl
Algorithm Hash digest
SHA256 bd1505503d438cf4934de1a5f275be16ccd963ec4f10a4cbc8f17d26e310891c
MD5 9d9a7e13aa43b3b19dbb3707985eb408
BLAKE2b-256 53148a3162aeb8a7252609f05c991448e30d4ab90bf03ebda1b3e2e478c99e8e

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