M
Manuel Graune
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
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