Recently, I’ve been doing quite a bit of reading about computer analysis of musical sound and some experimentation. But there wasn’t really anything I knew of that fit my desires for an experimental platform. Python + numpy provided a good combination of a pleasant language and signal processing ability. But beyond that I wanted an interactive environment that created a persistent record of what I was doing. And that means the ability to edit: to go back and fix up mistakes and add comments. Because a literal transcript of a shell session is worthless… it’s full of typos and dead ends. Also, I wanted inline plots and images. In essence, I wanted something like the Mathematica notebook user interface, but for Python.
The inline plot part can be found in Nicolas Rougier’s Pylab GTK Console, but other than that, it’s just the standard Python interactive mode in a GTK+ window. IPython has a lot of features but it’s still a shell in a terminal. So, I decided to create something myself. A couple of months of occasional evenings and 4000 lines of Python later, Reinteract is beginning to shape up. A screencast of it in operation can be found below:
I’m not ready to make a tarball release yet, but you can get the code out of git. (Instructions here.) The chances of it working out-of-the-box on a recent Linux system are pretty good. In theory, it should be completely portable to Windows and even to gtk-quartz on OS/X, but figuring out the details would take some work.
P.S. – Python shell envy within the Online Desktop / Mugshot team? It’s really a pretty different sort of thing from Colin’s project.
36 Comments
Cool!
Noticed a typo in trying it out section (the git clone fails if you just copy&paste). s/fishoup/fishsoup/ 🙂
Typo fixed. Thanks Martin!
Wow, this is insanely sweet. In the past I really wanted a tool like this, and I think now I need to find an excuse to want one again.
Awesome work, Owen!
Looks pretty awesome. I somewhat amazed something like this didn’t already exist, what with the great mountain of stuff the scipy people seem to have produced.
Wow. That looks totally awesome. Defnititely something I’ll find use for in my studies.
Very impressive !
I hope it will be package one day for most distributions.
Nice work, Thanks a lot !
Looks amazing 😀 I will definitely be keeping my eye on this software.
Awesome. Really awesome. Wow.
What’s needed to get custom painting for a Python class? Which interface has to be implemented?
Wow.
Really cool, neat, clear & consise démo.
Thank you.
This is pretty similar to the “notebooks” of SAGE (http://www.sagemath.org/), but obviously much more lightweight, and doesn’t use a Web browser.
It seems there is a bug with special characters for me. Hitting a § (for example) immediately crashes the application with this traceback:
/home/tnorth/../reinteract/reinteract/lib/reinteract/shell_buffer.py:1012: GtkWarning: /tmp/buildd/gtk+2.0-2.10.13/gtk/gtktextiter.c:3859: Incorrect byte offset 1 falls in the middle of a UTF-8 character; this will crash the text buffer. Byte indexes must refer to the start of a character.
end.set_line_index(end_index)
Gtk-ERROR **: file /tmp/buildd/gtk+2.0-2.10.13/gtk/gtktextsegment.c: line 196 (_gtk_char_segment_new): assertion failed: (gtk_text_byte_begins_utf8_char (text))
aborting…
That’s excellent, I’m very impressed 🙂 I’m sure I’ll find use for something like this in the future…
This is just awesome! I definitively will keep an eye on this project.
Is the screencast available in an open format?
Very nice work. If it’s not already, I recommend making this compatible with matplotlib (i.e., adding the ability to set matplotlib as the plotting back-end), since it seems to be the default plotting library for scientific and engineering Python applications.
Matthias: Custom results are pretty simple. The CustomResult base class has a single method create_widget() that you override. Then the widget is inserted into the buffer. I’ve some thoughts of extending it to have a two-way link with the statement that created the result, so you could interactively adjust the output and have the statement updated to match.
TNorth: Yep… I had some indecision about whether to work internally with byte strings in UTF-8 or Python Unicode strings, and I need to go back and clean that up. I’ll put it at the top of my list.
Yannick: Sorry, no. I didn’t know of a solution that would easily give me both swf and and Theora, and swf was the priority for quality and wide-viewability. I’ll definitely try to figure out how to do both next time. I would be interested to know if the screencast works with free swf players like swfdec or gnash.
Have a look at the Symbide project. That is another gui frontend to python. These two projects may gain from working together.
http://code.google.com/p/symbide/
When I was doing image processing / generation with PIL I thought it’d be a neat idea to somehow display images in the interpreter inline (to quickly check results). To do this in Reinteract all you need to do is have your object inherit from reinteract.CustomResult? What about in the case of a class that’s already defined elsewhere? (in PIL’s case the Image object)
What’s the best way to stay up to date on how well Reinteract is coming along? Or are you finished with it for now?
Very nice !
Just an idea : add the ability to detach the custom result from the editor (say : put it in a handlebox)
Yay!!! I’ve hacked a small patch to make it run on Maemo. Please take a look:
http://pastebin.ca/769791
It would be great if we had this running in a Nokia Internet tabled device, specially the new N810 with keyboard.
Excelent work! Thank you very much!
Steve: http://taschenorakel.de/gitweb/?p=playground;a=blob;f=reinteract/reimage.py

I’ve done a preliminary fix to the issue with utf-8 characters. It fixes the crashing but still has some warts.
git-repository here:
git clone http://ril.endoftheinternet.org/~jojkaart/git/reinteract.git
Displays fine for me in Gnash on Ubuntu gutsy. The audio kept cutting out, but I think that’s because of my net connection being heavily used rather than anything to do with you 🙂
Looks great. I think could be in very useful for my physics classes/research.
Keep up the good work!
Thanks this is great! – I have been wishing python had something like this for ages – just didn’t have the skill to do it myself..
Steve: I’ve definitely thought about having a plugin system where you could register special handling for different types of result object. For now, as Mathias demonstrated, you can create a function that just wraps up an object in a CustomResult.
Ben: That’s a good question. For now, I’ve created a special category in my blog, so you can subscribe to https://blog.fishsoup.net/category/reinteract/feed
in a feed reader. If I later create a mailing list, I’ll blog about it.
Joonatan: Many thanks for the patch! I decided, after thinking about it a bit, to go the opposite route and keep the internals as byte strings. I’ve pushed a patch fixing up the tokenization for that. I’ve also fixed the encoding on parsing, so it’s possible to use non-ASCII characters within strings and not have them mangled.
I’m new to Python, but this looks great. I’ll definitely give it a try. Thanks!
@Owen:
You may like this howto for going from swf to other formats:
http://hublog.hubmed.org/archives/001557.html
Awesome thing! What do you think about adding some usual shell shortcuts (like Alt-b for going word backward, Alt-f – word forward, C-w – delete word backward, Alt-d – delete word forward and so on)? This will make reinteract more usual for any familiar with usual shortcuts. 🙂
Very cool! Is there a way to change the prompts so I can past code directly into doctests? (Ie, get >>> and … instead of your colored boxes)
Wow, this is pretty cool.
Awesome. I just hacked a simple “rehtml”:
http://advogato.org/person/eopadoan/diary/7.html
Very nice indeed. Do you realize that you’ve in a very real sense created a data-flow language from a scripting language.
Many data flow languages are visual and include pd (pure-data) and Max/MSP. They all have this always-on-ness that is presented here.
The always-on-ness makes a language very useful for gestural programming. By this i mean, that one can change them and see/feel/hear the result immediately. Something of the feedback and artist uses in see their hand gesture on the canvas. This is exceptionally important for programming as composition, for example in generative sound composition.
Once again brilliant.
Another advantage of visual data flow languages is that they have many tops (main loops if you want to thing of it like that)
This means that creating parallel action/processing is very easy. This is also very import in creating a multi-layered work.
Can reinterpret have multiple instances that live in the same sand box?
Brady: I think you are on to something with the idea that programming in an environment like Reinteract is fundamentally different than just writing a static script. We all know that the faster the cycle time is, the more productive the programmer is. Reinteract can reduce the cycle time to basically zero.
Because I see Reinteract as a tool for creating records of computational experiments, I’m not necessarily so interested in going completely dynamic … you move a slider, the playing sound changes. It’s related, but a different emphasis. That also reduces the interest in multithreading and parallelism… to me the main reason for adding threading would simply be to not block the users during a long-running computation.
I should point out that there is no real data-flow analysis going on in Reinteract currently. Each statement is considered to depend on all the statements above it. Better dependency analysis could be done and probably eventually will be done, but I haven’t found a huge need for it yet.
Owen: i don’t think data flow languages do any analysis. And theoretically single threaded. Their trick, ask far as i know from reading documentation of pure data ( but not it’s code), is an event scheduler that runs at the top, of the data flow chains, each of which is deterministic.
Timers or UI actions seed this scheduler, otherwise nothing happens. And nothing interrupts an execution chain until it’s stack is done.
2 Trackbacks/Pingbacks
[…] | 0 comments | 0 pingbacks | python, shell Симон Виллисон дал ссылку на reinteract, интерактивный интерпретатор для питона, можно даже […]
[…] who have been reading my blog for a while may remember Reinteract. I haven’t written anything about it here for a while, but I’ve still been working on […]