Powerful yet easy command line calculator.
Project description
cli-calc
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
$
-
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:
-
standard operators
-, >>, ...
-
standard math library
cd, log, sin, sinh, gamma, pi, e, tau, inf, nan...
-
cmath
phase(complex(-1.0, 0.0)), and then most of the above with complex numbers.
-
random
random, choice(['win', 'lose', 'draw']), mean, ...
-
built in functions
max, help, sum, ...
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
Note on Shields
- 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
- Fully typed with annotations
- Checked with mypy
- Packaging PEP561 compatible
Tools
Python Packages
- pypi.org Python Package Index
- pythonrepo.com Popular Python Libraries
- poetry add
- poetry update
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
- pytest test framework
- The Magic Tricks of Testing by Sandi Metz (Talk) on what to test, and what not
Continuous Testing & Integration (CT & CI)
Integration as in: Deployment and Integration testing.
-
- pytest & coverage (yml) pytest @ python-version: ['3.7', '3.8', '3.9', '3.10']
- misspell (yml)
- codeql-analysis (yml)
-
Alternatives to github actions
- tox test and deploy
- travis test and deploy
- coveralls.io coverage
Build and publish to pypi
- make Makefile automate above
- poetry version bump bump version
- poetry build wheel
- poetry publish to pypi
Following Semantic Versioning
- Semantic Versioning
- semver Python Package
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
- gh GitHub on the command line
- tickgit Not used, but collects TODO from source code
IDE
Shell
Documentation
- Markdown lightweight markup language
- sphinx Python documentation Generator
- doc8 opinionated style checker for rst
- readthedocs document style and service
Metric
- shields for Shields and Badges
- issuehub.pro Label Guide
- cloc for SLOC
Jason Query for Makefile and Shields
Teaching Python Development
cli-calc Examples
- github actions (cli-calc)
- make Makefile (cli-calc) automate above
- cli-calc
NvK Tools
License
Credits
This project was generated with wemake-python-package
. Current template version is: d06993f12e3ffad79652a2aec86189dee92d94dd. See what is updated since then.
Project details
Release history Release notifications | RSS feed
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 cli_calc-0.2.21-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d51ff648433cdc3afc3a918cd39c014323effca40b5e06d6484149284340fded |
|
MD5 | fcaba7715a87b12556d9327ab7fe37fa |
|
BLAKE2b-256 | 728bafe4313587a8c5fd1cc5e7c438b6ebfb02aa16719565275aab144f9a76a7 |