Using Python 3 as a screen-logging command-line calculator
I enjoy using the interactive Python console as a calculator, but typing
python3 and then
from math import * was annoying. So I scripted it into a simple command I’ve named
cpy. Maybe someone else can use it.
#!/usr/bin/env python3 import code import readline import rlcompleter # Directly import all the math functions from math import * print("Interactive Python 3 with 'from math import *'") vars = globals() vars.update(locals()) readline.set_completer(rlcompleter.Completer(vars).complete) readline.parse_and_bind("tab: complete") shell = code.InteractiveConsole(vars) shell.interact()
The list of functions available in the Python3 math library. The script is also available as a Github Gist.
$ cpy Interactive Python 3 with 'from math import *' Python 3.4.3 (default, Oct 14 2015, 20:28:29) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> pi*5**2 # sqft area of a 10ft circle 78.53981633974483 >>> sqrt(100/pi) # radius of a 100 sqft circle 5.641895835477563