Wednesday, July 26, 2006

IronPython 1.0 RC1 released

It was announced on the IronPython mailinglist today, that the first release candiate of IronPython 1.0 is available for download. IronPython is an implementation of Python written in C# and designed to run on an implementation of CLI like Microsoft .NET 2.0 CLR or Mono 1.1.16.1+. The goal of the IronPython team is for 1.0 is to be compatible with CPython 2.4. But they have included some features from CPython 2.5 that are enabled with the -X:Python25 commandline switch. These include PEP 308: Conditional Expressions and PEP 343: 'with' statement.

As well as many bugfixes, the other positives for me are:
  • In some cases code execution is faster, and it launches 2.5 times faster.
  • Since I do alot of my IronPython work with Mono, I can now finally exit using Control-D
If you are in Sydney this Thursday 27 July, why not come to the Sydney Python Users Group meeting and hear me talk about my IronPython experiences.

Tuesday, July 18, 2006

Overriding IronPython's built-in modules

For those who haven't used IronPython, batteries are not included. After installing IronPython, you need to copy, symbolic link or update sys.path with the CPython standard libs if you want to do more than script .NET/Mono classes. As the various beta's of IronPython have been released, some of the standard library modules are being coded in C# and included in the IronPython Assembly. The socket module is one of these. But as of Beta 9, the socket module does not implement the getaddrinfo function. Many Python network modules expect this function and I was having trouble with a script I was trying to port because of it. But I knew that Seo Sanghyeon had written a IronPython socket module prior to it being included as a built-in and it had getaddrinfo. Since the calls to socket were in other third party python modules, I couldn't just rename socket.py and import it the new name. I needed to override the built-in but how? Then I remembered a post by Fuzzyman about including Python code in an assembly. So by using the code in the top of my script I was able to use the python version of socket.

import imp
import sys

moduleName = 'socket'
moduleSource = './Lib.ip/socket.py'
newModule = imp.new_module(moduleName)
execfile(moduleSource, newModule.__dict__)
sys.modules[moduleName] = newModule

import socket

Of course, there may be a better way.

SyPy Meetup Reminder Thursday 27 July

The Sydney Python group is having its first meeting for the year on Thursday July 27.

Usual time and new place:

Thursday, July 27, 2006 (6:30 PM - 8:30 PM)

The "new" University of Sydney School of IT Building.

Thanks to Bob Kummerfeld for arranging this.

The venue is approx 1 km from both Central and Redfern stations.

Use the entrance from the University side, not the Cleveland St side. If you come from City Rd, enter the Seymour Centre forecourt and follow the curve of the new building down to the foyer entrance.

http://www.cs.usyd.edu.au/~dasymond/index.cgi?p=Map

Please reply to this message (or click the appropriate radio button on http://upcoming.org/event/89388) if you will be coming.

Talks:

Graham Dumpeton on what is coming in the next major version of mod_python (3.3). This version of mod_python should represent a significant improvement over previous versions in certain areas with ramifications on stability. New features have also been added which make mod_python a bit more flexible than it is now and more useable in the way that Apache modules should be able to be used. Result is that mod_python can truly be used for more than just a jumping off point for stuff like WSGI and all those Python web frameworks that
keep popping up every day.

I will be giving a talk on my experiences in using IronPython with .NET and Mono.

The talks will be 15-20 minutes in length with plenty of time for questions.

See you there.

Monday, July 17, 2006

IronPython and the moving API

Last week the IronPython team released IronPython .0 beta 9. This should be the last beta before the release candiate.  Also  they  say they have finally locked down  the Hosting API. This has an impact on what I have been working on, which involves hosting the interpreter within an ASP.NET handler. Thankfully the final Hosting API has returned to a more pythonic API rather than imho, the ugly API of beta 8.

With each beta release, there seem to be just enough changes in how to do things that writing an article on IronPython that will work with later beta's is a challenge. Even the IronPython team have been having trouble keeping their tutorials that ship with the beta in sync.

For example, on the IronPython mailinglist, Michael Foord pointed out a link to an article on IronPython. It is well written and has some interesting code examples that could attract a .NET programmer to give IronPython a go. I am not sure when the article was written but at least one code example doesn't work as a python list is no longer automatically converted to an array when passed as a argument to a .NET class. So to get this example to work for beta 9:

import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import *

class MyForm(Form):
def __init__(self):
Form.__init__(self)

Button1 = Button()
Button1.Top = 10
Button1.Left = 10
Button1.Text = "One"

Button2 = Button()
Button2.Top = 50
Button2.Left = 10
Button2.Text = "Two"

ctrls = [Button1, Button2]
self.Controls.AddRange(ctrls)

f = MyForm()
Application.Run(f)

You need to modify the line:
ctrls = [Button1, Button2]
to:
ctrls = System.Array[System.Windows.Forms.Control]( (Button1, Button2) )

You will also need to add
import System
after the
import clr
line.

The author of the article provides the above syntax as an alternative solution, but as of beta 9 it's the only solution. I can understand why these changes have needed to happen so late in the beta programme, but it's a shame we miss a chance to bring more programmers under the spell of Python because the code didn't work.

Monday, July 10, 2006

What does the World Cup Football and OSDC 2006 have in common?

While watching the second half of today's final as Italy and France played towards a penalty shootout, I made the most of my time and submitted my paper proposal for OSDC 2006. If it is accepted I will be speaking about using Agile Languages in this case, IronPython and Boo with Mono.

Alan Green has submitted one, now just need Andy Todd to submit one, and the gang of 3 could be all speaking at OSDC again.

Saturday, July 08, 2006

Another weblog to maintain

To not pollute this blog's Atom feed with too much detail on my CLI adventures, I have created a new blog.

Now if blogger had category filters, I wouldn't have to do this. Of course, I could stop mucking around and get a domain name, find a web host and do my own.