REPIC is a Python function that will let you print output to comments inside the current file. It stands for Read, Evaluate, Print In Comments.
Install Python and then in the terminal install via:
pip install REPIC
Given a file test.py with the following content:
from REPIC import REPIC
test = [1,2,3] + [4,5,6]
REPIC(test)
After running the contents of test.py become:
from REPIC import REPIC
test = [1,2,3] + [4,5,6]
REPIC(test)#OUTPUT: [1,2,3,4,5,6]
Why in the world did I build this? I'm a huge fan or REPLs, but it's hard to save the output from them and go back and edit it later. iPython is great, it's probably the environment I develop Python in fastest, but with all the HTML and javascript frontend there's a lot of dependencies and new interfaces. REPIC lets you stay in your text editor or terminal environment and still get that convenient combination of code and output.
This library works great with Python files edited with Sublime text. You run the file and the output shows up immediately. This might not be the case in every editor and Python environment since this code uses a lot of hackish features.
iPython was a big inspiration, and its repl sessions can be saved if you prefer that kind of interface.
Thanks to users on stackoverflow for info on how to pull line numbers out of currently executing code. Thanks also to this thread discussing in-place rewrites of files in Python.
On a more philosophical level, this was inspired by Don Knuth's literate programming, REPLs, and what appears to be the first "Notebook" interface tweak to the REPL in Mathematica.