๐ง This Python package is a WIP.
Still TODO:
โ Publish to PyPi/conda-forge
โ Make it work for older versions than 3.10
โ Test with macOS/Linux
โ Test with Jupyter
Printi watches what you print, and if it sees a number that can be displayed in a more insightful way, it will tell you.
For example, the last line in the code snippet below is printi
telling you
that -2.4674011002723395
is very very close to -ฯยฒ/4
:
>>> import cmath
>>> import printi
>>> printi.watch()
>>> cmath.log(1j) ** 2
(-2.4674011002723395+0j)
๐ก -2.4674011002723395 โ -ฯยฒ/4
The printi
function is a drop-in replacement for print
. It has the same
API as the builtin print
function.
To use printi
as a function, you'll need to use from printi import printi
(for all
other methods it is enough to use import printi
).
Rather than use printi()
directly, you can tell it to watch stdout
.
You can add this to your startup script
referenced by PYTHONSTARTUP.
Example Python startup file using Printi:
# This file is referenced in PYTHONSTARTUP
import sys
from pathlib import Path
sys.path.append(str(Path.home() / 'path/to/printi/src'))
from printi import printi
printi.watch()
Now when you start any interactive session, Printi will be watching.
Printi will stop watching.
Updates the configuration options for Printi. All possible keys, and their defaults are:
printi.update_config(
min_denominator=3,
max_denominator=100,
tol=1e-9,
symbol='๐ก',
specials={
math.pi: 'ฯ',
math.tau: 'ฯ',
math.e: 'e',
},
)
min_denominator
is the minimum denominator.max_denominator
is the max. If this is set too high, you'll get false positivestol
is the tolerance. This is passed tomath.isclose
asrel_tol
symbol
. Change this if you don't like the light bulb. Why don't you like the light bulb?specials
is a dict offloat
/string
pairs that will be added to the existing dict. To remove a key, passNone
as the value. Example below:>>> printi.update_config(specials={1.2345678: 'ฮป'}) >>> 'How do you like 1.2345678?' 'How do you like 1.2345678?' ๐ก 1.2345678 โ ฮป
Printi will only find 'representations' in the form a ยฑ b * c ** d where
a
is an integerb
is a fraction (respecting min/max denominator)c
is either one of the 'special' values, or a digitd
is a selection of positive and negative integers and fractions
Check out the tests in /tests/test_printi.py
for lots of examples.
- Run
pipenv run test
to run the tests - Run
py -m build
to build