Few IronPython impressions and a quick guide

I've been messing with IronPython lately. It's a .NET, microsoft-supported [stop throwing tomatoes at me! Ms-PL is an OSI-recognized OSS license! Ouch, stop that!] implementation of Python, somewhat like Jython is a Java implementation. The same person is behind them both, by the way 🙂

What is it good for? Well, accessing the whole .NET framework with Python code is quite a strong feature. IronClad project aims to allow accessing CPython (the popular implementation) binary modules, not sure how mature it is.

First impressions? 2.0RC2 seems pretty mature. Most of the "random" .NET classes I've been trying out seemed to work flawlessly. Load time is a bit slow. But all in all, it seems pretty good.

And now to few specific notes, that a CPython user might need as of version 2.0RC2:

Loading .NET assemblies howto

note that mscorlib is needed for many common namespaces, such as Microsoft.Win32. In MSDN, the "assembly name" is specified for each namespace, so it's easy to find out.

Python logging module bug

The famous logging module currently throws an exception instead of printing lines. Here's a workaround till they fix it:

[see Michael's comment below]
_winreg module problem with REG_BINARY type

The CPython _winreg implementation works fine, however in IronPython there's currently a little problem: "high ascii" (>128) chars are getting screwed because of some converting/encoding problem (uses System.Text.Encoding.ASCII which is 7bit aware). My workaround was to use directly the Microsoft.Win32.Registry implementation, and manually convert the returned Microsoft Byte Array to native Python string of bytes. If you need the code, comment me and I'll add it.

Compiling to DLL/EXE

I was looking for some "py2exe" compiler, but found out that the compiler itself is available as an IronPython class, and anyone can call it from their own Python script to fit their needs. Still, I use the pyc code (command line compiler). Note: find the latest version of this script, cuz old versions (IronPython v1.x don't fit!). Current latest hides in "IronPython 2 Beta 4" release.

Note: sometimes EXEs don't behave exactly the same as in the interpreter:

  • sys.argv bug: would probably be fixed soon
  • "clr.AddReference()" lines are sometimes (always?) not needed when using the interpreter, but are always required in EXE.

I find a "make" system pretty needed for IronPython.

Writing GUI

Windows.Forms is an integral part on .NET, and as such, is native to IronPython. IronPython Studio aims to allow nice GUI drawing tool (ok ok, an IDE). Still a bit buggy (I've lost 1hr annoying-design-work cuz it wasn't saved well), but it surely helps designing.


Debugging tools: haven't checked that area yet.

Sleep now.

3 thoughts on “Few IronPython impressions and a quick guide

  1. Michael Foord

    "The famous logging module was re-implemented in IronPython"

    Actually it wasn't - the IronPython 2 installer includes the Python 2.5 standard library and the logging module included is the vanilla Python logging module. The change you describe is needed because of the logging module's use of sys._getframe which isn't available in IronPython.

    As for the _winreg bug - have you reported it?

  2. Michael Foord

    For debugging I recommend good unit tests (no seriously!).

    You can use the .NET debugger from IronPython Studio apparently, and also from Visual Studio 2005 professional if you have the SDK installed (not sure about VS 2008).

    For tracking memory related problems we've had a lot of success using Windbg.

  3. Oren

    Michael, thanks for your comments, especially the correction about logging module - I got it wrong, I'll fix that in the article.

    About _winreg bug, right. I will report that.

Leave a Reply

Your email address will not be published. Required fields are marked *