A few weeks ago I started to learn Go (aka Golang). I enjoy it very much, I think it’s a very nice and logical language. It is similar to Python in several aspects, so it’s not difficult to start after Python.

If you watch some videos about Go, you will notice that most presentations are made with the same presentation software. And the most interesting part is that you can include Go code snippets in the presentation that you can execute with a button click. The output is also shown. That is, if you want to show some code, you don’t need to jump around between a terminal and the presentation; everything is at one place.

Problem
You want to do the same with Python code snippets. You want to use this presentation system and you want to embed runnable Python codes in it.

Solution
These presentations are done with the Go package called present. Here I won’t explain how to set up Go on your machine, I leave it as an exercise (link1, link2). Once you have Go installed on your machine, install the present package:

$ go get code.google.com/p/go.talks/present

The good news is that present is prepared to run scripts (whose first line starts with a shebang). The file that is responsible for executing Go programs and eventually Python scripts is here: $GOPATH/src/code.google.com/p/go.tools/playground/socket/socket.go.

However, I found a bug in socket.go (reported here). The last line of the function shebang() must be changed (Update 20140227: my patch has been integrated since then, so if you install the present package, you’ll have the correct version):

old (buggy):

return fs[0], fs[1:]

new (corrected):

return fs[0], fs

After this compile present. Enter the directory $GOPATH/src/code.google.com/p/go.talks/present and execute the command “go install“. It will place the binary “present” in the folder $GOPATH/bin.

Update (20140215) — convert presentation to PDF
You can convert your presentation to PDF easily. Navigate to the first slide in Firefox (I prefer this browser) and go to File -> Print…. Select “print to file”, change the page orientation to “landscape” and hide all the headers and footers (blank). Firefox will print every slide, each slide on a new page.

Update (20140331)
Right now I’m at the Write the Docs conference in Budapest, Hungary. Today I gave a lightning talk with the title “Using Go’s present with Python code snippets”. The presentation converted to PDF is here.