Home > python > Using Go’s present with Python code snippets

Using Go’s present with Python code snippets

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.

Example: http://www.youtube.com/watch?v=f6kdp27TYZs at 6:57.

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.

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.

Try it out
I put a simple demo presentation here: https://github.com/jabbalaci/go-present-for-python . Download the files and launch "present" in the directory where the downloaded files are. Visit and check out the demo that contains a Python and a Go code snippet. Don't forget to click on the "Run" buttons :)

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 (20140218)
This blog post got included in Go Newsletter Issue #21 (Feb. 2014). Awesome!

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.

About these ads
Categories: python Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 65 other followers

%d bloggers like this: