python as pen and paper substitute

James Stroud nospamjstroudmapson at mbi.ucla.edu
Tue Apr 6 20:14:39 EDT 2010


Manuel Graune wrote:
> Hello everyone,
> 
> I am looking for ways to use a python file as a substitute for simple
> pen and paper calculations. At the moment I mainly use a combination
> of triple-quoted strings, exec and print (Yes, I know it's not exactly
> elegant). To clarify, I just start an editor, write a file that
> might look something like this:

I wrote a module called pylave, which is meant to be a 
parser-evaluator-solver for scratch paper-like calculations. It has 
strict operator precedence, knows a variety of common operations, and 
respects parenthetic grouping. It is designed to evaluate ini files, 
which can have syntax highlighting depending on your text editor. 
Pyparsing is required.


Here is a pylave example:


% cat test.ini
factor     = 2
wwww       = minor_axis / 2
www        = 69.69 + wwww
height     = 10
apex       = epicenter // height
major_axis = epicenter + 2*radius / sin big
minor_axis = epicenter + (total / 14) % (length-1)
epicenter  = 44
radius     = ((14 + length)/2 + height)*breadth
length     = width + 5
width      = 2**2 - factor
total      = big*(radius + 14)
big        = abs (sin (5e+8))
breadth    = 2*length + height
overlap    = abs (1 + 1)
nexus      = sin (5e-8)
plexus     = sin (5e8)


% ./pylave.py test.ini
breadth : 24
www : 93.8350093235
nexus : 5e-08
big : 0.284704073238
major_axis : 3547.35712408
height : 10
radius : 492.0
plexus : -0.284704073238
total : 144.060261058
epicenter : 44
apex : 4
overlap : 2
wwww : 24.1450093235
width : 2
length : 7
factor : 2
minor_axis : 48.290018647


It is not perfect but if it will help, I'll cheeseshop it.

James



More information about the Python-list mailing list