python as pen and paper substitute

Manuel Graune manuel.graune at koeln.de
Tue Apr 6 14:40:40 EDT 2010


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:

---------snip-----
code="""
a = 1
b = 2
c = 3
result = a + b
"""
exec(code)
print(code)
print("result     =\t", result)
print("result + c =\t", result + c)
---------snip------

and feed this to python.

For what it's worth, this approach achieves what it's supposed to,
which is to get some basic control over the output and
to avoid to much redundant typing.

Now I'm wondering if there is a more elegant method to achieve this which
e. g. does not mess up the syntax-hightlighting, does not use exec()
and avoids the redundant mentioning of the variable that holds the
acutal code. Since I have complete control over the input and the files
are not supposed to be shared, security should not a problem and
simplicity is criterion #1.


So, does anyone have tips?

Regards,

Manuel

P.S.: I know Ipython. In the cases where I use the hack shown above
it just does not fit my workflow




-- 
A hundred men did the rational thing. The sum of those rational choices was
called panic. Neal Stephenson -- System of the world
http://www.graune.org/GnuPG_pubkey.asc
Key fingerprint = 1E44 9CBD DEE4 9E07 5E0A  5828 5476 7E92 2DB4 3C99



More information about the Python-list mailing list