python as pen and paper substitute

Manuel Graune manuel.graune at koeln.de
Tue Apr 6 17:01:51 EDT 2010


Thanks for your reply.

Johan Grönqvist <johan.gronqvist at gmail.com> writes:
> Manuel Graune skrev:
>> 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.
>>
>
> I do not understand your use-case, but as one way of performing the
> same task as the above code, without sacrificing syntax-highlighting,

The use-case is acually fairly simple. The point is to use a python
source-file as subsitute for scrap-paper (with the opportunity to
edit what is already written and without illegible handwriting).
The output should  1) show manually selected python code and comments
(whatever I think is important), 2) show selected results (final and
intermediate) and 3) *not* show python code that for someone only
interested in the calculation and the results (and probably not
knowing python) would just be "noise" (e. g. "import"-statements,
actual "print()"-functions, etc.). 

> from __future__ import with_statement
> import sys
>
> def print_source():
>     print sys.argv
>     with open(sys.argv[0]) as file:
>         for line in file:
>             print line,
>
> [...]
>
> print_source()
> print("result     =\t", result)
> print("result + c =\t", result + c)


As far as I understand this code, all of this would be printed as well,
which is exactly what I do not want.

Regards,

Manuel


-- 
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