My Life As A Blog

Iron Python at QCon

leave a comment »

I spent yesterday on the Microsoft stand at QCon 2010.  I took a few Iron Python samples with me to show to those who are interested.  I wanted to be able to show three things:  .NET runs Python, Python extends .NET and Python runs .NET.

.NET runs Python

To show that .NET can run Python I used the Text Processing sample I’ve blogged about before.  I’ve subsequently added optparse to it so that it can be driven from the command line.  The point of this sample is that it uses standard Python libraries, the whole application is written in Python (there’s a little XAML to describe the UI) and runs on the DLR courtesy of IronPython.

Python extends .NET

For a simple demonstration of extending a .NET application with Python, I took the sample application described here.  This application allows the user to write Python (at runtime) that interacts with the application.

Python runs .NET

The last sample was an adaptation of the code here that reads a Twitter feed.  Rather than use Twitter (with all the shortened urls and abbreviations) I decided to use an RSS feed from the BBC to create an Iron Python newsreader.  The code is remarkably simple:

import clr

from System.Speech.Synthesis import SpeechSynthesizer
from System.Xml import XmlDocument, XmlTextReader

xmlDoc = XmlDocument()
spk = SpeechSynthesizer()

itemsNode = xmlDoc.DocumentElement.SelectNodes("channel/item")
for item in itemsNode:
  print item.SelectSingleNode("title").InnerText
  news = "<?xml version='1.0'?><speak version='1.0' xml:lang='en-GB'><break />" + item.SelectSingleNode("description").InnerText + "</speak>"

This is Python using standard .NET libraries to show how a Python programmer has the .NET framework available to them through Iron Python.


The final thing I talked about is Gestalt, which allows you to run Python (and Ruby) in the browser.  It does this by using the DLR, which is part of Silverlight – this is all encapsulated in javascript.


Written by remark

March 12, 2010 at 7:21 pm

Posted in .NET, Events, Microsoft, Python

Leave a Reply

Fill in your details below or click an icon to log in: Logo

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

%d bloggers like this: