note: sorry about the huge fonts. working on it.

sliderepl - slide read eval print loop

sliderepl is a little hack for hands-on Python code presentations, tutorials and classes. sliderepl bootstraps a file of "sample code" into an interactive Python session. Just drop some section delimiters into your code...

### slide::

hello = 'hello, world'
print hello

### slide::

print hello[:6] + ' and goodbye!'

### slide:: end

...and sliderepl will load up an enhanced >>> session that injects the code into the session a section at a time. The injected code looks and runs just as if the user had typed it themselves at the >>> prompt. It's even added to their readline history. Users can just follow along the presentation, watching the output a section at a time, or dive in and explore the code being presented.

Features

  • Doesn't interfere with your sample code- just add some delimiters in comments
  • Develop slides naturally in your regular text editor- it's just a .py
  • Sample code is still readable, copy-and-pastable, whatever.
  • Directly embeddable in the sample code file without polluting the code environment
  • Or usable as an import
  • Users just run python samplecode.py and get a >>> shell
  • The shell has extra commands: next slide, goto slide, show slides, etc.
  • Readline support with tab completion and input history integration
  • Can do bullet-point-style slides as well
  • Easily extensible!
  • Small!

Download

2008-03-14 0.12 "Pi Day"
sliderepl.py

sliderepl is released under the MIT License. Go nutty. Patches welcome.

Requirements

Tested with Python 2.3 through 2.6a, on most platforms. (Thanks to #pdxpython for pre-PyCon testing and all the folks in my PyCon tutorial for trial by fire!)

Documentation

Docs are in sliderepl.py itself, in presentation format.

Why

I whipped up sliderepl for my PyCon 2008 tutorial session- an advanced, hands-on session with a ton of sample code & hands-on exercises. With a tight schedule, I didn't want to lose any time getting people going with their environments. At the same time I didn't want to impose an environment or working style on the most advanced users.

Future

I received a ton of positive feedback from the tutorial participants at PyCon (thanks!). sliderepl is very usable for presentations right now, but there are a few features I want to add before adding it to pypi.

  • Some ANSI terminal support, at minimum bolding of sliderepl-initiated messaging.
  • Refactor command argument inspection to allow optional arguments (e.g. toggle commands instead of explicit 'setting on' 'setting off')
  • Maybe a -*- throws_exceptions -*- magic tag to ease testing.
  • An 'updater' script that automates updating embedded sliderepl in text files.
  • On-line docs
  • Move sliderepl from my private svn area to a public repo

Advice

Some observations from my own limited experience inflicting sliderepl on a big room full of folks:

  • Provide some sort of cue so that users know when to continue on to the next slide. At PyCon, preparation time constraints led to some sections of the tutorial having cues on the projected slides and some sections without. The cued sections were much smoother.
  • The environment may need a spoken introduction for your users. I got a great "oh... oh!!!" moment at PyCon just by suggesting that a user hit the up arrow a few times- seeing that the readline history matched the >>> output made it click.
  • Separating monolithic sample code into multiple scripts is useful.
  • Use python scriptname.py --run-all to catch syntax errors in your slides. To find errors, grep for Traceback. Originally sliderepl considered slide exceptions fatal, but then I needed a slide that showed exceptions being thrown. See "Future"
  • Extend Deck! Deck.start() is a great place to manipulate sys.path. For the tutorial, I included a .zip of a required library with the code samples. In the .start(), I just pushed the .zip on to the head of sys.path and attendees were up and running without any installation or version conflicts.
  • Don't depend on the wireless network at your presentation. Load your code slides onto a handful of thumb drives or stack of cds in advance.

Author

Jason Kirtland <jek@discorporate.us>

License

sliderepl is available under the MIT License

Copyright (c) 2008 Jason Kirtland

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.