The best desktop calculator app is Python
· 2 min · #development
Not that anybody was wondering about this, I know. A hotter topic would be text editors, or variables naming
conventions, but I just feel like talking about this now.
Last year I stopped using the default GUI calculator on my computer, in favour of a much easier and convenient
Python shell.
The pros:
- Variables
- Complex equations on one line
- Persistent history across consecutive sessions
- Can use constants like
e
,pi
just by typing - Functions like
log
,degrees
,radians
...
Might not seem much but these little things truly help me save time and patience for other tasks.
The cons:
None that I can think of, apart from the fact that I just checked and... all those things above can be done with
the GUI calculator too (at least with mate-calc). This post is a lie.
By now, you must be sold on the idea and might be wondering what are the steps needed to achieve this nirvana of calculations productivity.
First things first. How to launch this improved calculator? Open a new terminal tab or window, type
pyth
— ... NO! Boring! Slow! You need a keyboard shortcut! I set mine to SUPER+C
(C
for... you know, "Can't believe how fast this thing is!") and bound it to the following
command:
xfce4-terminal --geometry=60x10 --command="python3 -q"
Of course, both the command and the way to set the shortcut depend on your system, the desktop environment and
the terminal you use, I just gave you the general idea.
The -q
option suppresses that annoying initial message about version and copyright, you're welcome.
As second and last step, you'll need to create a python configuration file at ~/.config/python/pythonrc
and put the following lines in it:
from math import log, log10, e, pi, sqrt, degrees, radians
All lines in this file will be executed whenever a Python shell is launched. This saves a lot of time, for
there won't be need to explicitly call these imports every time you want to use the calculator.
Obviously, why stop there? I added a few more to my configuration, just to make things smoother, and even defined
a couple of custom functions:
from time import sleep
from sys import exit
from datetime import datetime
def formatted_date():
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
This clearly goes beyond the scope of a calculator, but I thought it might be nice to show the potential of Python's configuration.