When I started to use Linux, GCalTool is my first calculator. SpeedCrunch should be next, then HC1. The latter two calculator are nice. I really like SpeedCrunch, unfortunately it’s QT2 and GUI.
A while later after I switched to HC, I realized that I already have one perfect calculator installed, Python. I didn’t really need graphing, but Python can do that, too.
1 Using PYTHONSTARTUP
If you only need +-*/, then you simply run python. If need more math functions. Here is so far I am doing.
First create ~/.pycalc.py with:
from math import *
Invoking python with PYTHONSTARTUP=~/.pycalc.py python. PYTHONSTARTUP is an environment variable which you can assign a file, Python will try to execute that file before it gives you the interpreter.
I use FluxBox and rxvt-unicode, so I have the following lines in ~/.fluxbox/keys:
# XF86Calculator
148 :Exec urxvtc -e bash -c 'PYTHONSTARTUP=~/.pycalc.py exec python'
Right now, ~.pycalc.py fits all my needs, I don’t need any helper functions or something else. Actually, I hardly press that calculator button (XF86Calculator) on my keyboard. I just grab that calculator on my desktop. The most advanced button I have pressed on that basic calculator is %. √? Never got a chance to press.
I believe many language interpreters could do the same. If you have a favorite language, try to use their interpreter, it could be the best calculator for you.
2 Using konch
konch is a command-line and configuration utility for your Python shells, whether it’s built-in, IPython, or BPython. It can help customize them and to achieve the same effect, a simple configuration file like the following would do well.
# -*- coding: utf-8 -*-
import konch
from math import *
# from https://github.com/sloria/konch/issues/2
context = dict(locals())
for k in ('konch', 'context', 'fname', 'locals_', 'globals_'):
if k in context:
del context[k]
konch.config({
'context': context,
'prompt': 'do the math > ',
})
[1] | http://houbysoft.com/hc/ is gone. |
[2] | I am not against QT, just don’t want to have many libraries on my system. The only QT program on my system is SMPlayer. I really hope someday it would support GTK. |
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.