Python Programming, news on the Voidspace Python Projects and all things techie.
The Tart and his Sole Scion
- Sole Scion project v0.1 : A 2D rigid-body Python game - "Version 0.1 merely bounces some circles off an inclined plane"
In true freetard style he's made the code available so that you can have fun too, but with a typically odd name....
Although he says he has only tested it with Linux, at Resolver Systems we've had it running on Windows.
Chapter 14: Extending IronPython with C# / VB.NET
I've just finished chapter 14 of IronPython in Action - well, finished a version I can send to my editor anyway. I had more fun writing this chapter than I expected. It's called "Extending IronPython with C# / VB.NET", and is all about writing class libraries in C# or VB.NET and using them from IronPython. This might be for performance reasons, for accessing features of the .NET framework like attributes or Linq that are hard to use from IronPython, or for simply making your class libraries as nice to use from IronPython as possible.
The table of contents for the chapter (pre-edit!) is:
14.1. Writing a Class Library for IronPython
14.1.1. Working with Visual Studio or MonoDevelop14.1.2. Python Objects from Class Libraries14.1.3. Calling Unmanaged Code with the P/Invoke Attribute14.1.4. Methods with Attributes through Subclassing
14.2. Creating Dynamic (and Pythonic) Objects from C# / VB.NET
14.2.1. Creating Dynamic Objects14.2.2. APIs with Keyword and Multiple Arguments
14.3. Compiling and Using Assemblies at Runtime
This is one of the nice things about IronPython, dropping down into C# to extend it is worlds easier than writing C extensions for CPython. There is no C API to have to worry about, and most of the normal C# you write will 'just work' when used from IronPython.
The chapter has five class libraries, each written in both C# and VB.NET. Inevitably in the process I learned more about both these languages.
VB.NET is not so bad, although more verbose than C# (semantically they're very similar of course). My favourite comparison is defining a method that provides iteration. In Python this is def __iter__(self):. In VB.NET it is Public Function GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator.
Although I love the dynamic goodness of Python, the C# syntax for properties and indexers is nicer than the Python syntax.
Next onto chapter 15, which is the final chapter. I've been looking forward to writing this chapter for a long time: it is on embedding IronPython in .NET applications and interacting with DLR objects from C# (and VB.NET).
Python in the Browser: Live Interactive Interpreter in an HTML Textarea
A while ago I experimented with an interactive Python interpreter that ran in the browser using Silverlight. Unfortunately a couple of bugs with the version of IronPython for Silverlight prevented it from working properly.
"Python in the Browser" is an interactive Python interpreter that runs in the browser, using Silverlight 2 and IronPython.
This is ideal for tutorials and documentation, where example Python code can actually be tried in the browser.
You can see a live demo of the current version at:
It requires Silverlight 2 Beta 2, and the Python version is 2.5. Builtin modules are available, but I haven't made much of the standard library available in the demo (they simply need to be added to the 'xap' file containing the silverlight application.)
Target browsers are Firefox 2 & 3, Safari and IE 7 & 8. (It won't work in other browsers until there is a version of Silverlight that works with them.) Silverlight 2 is currently only available for Windows and Mac OS X, with the Firefox, Safari or IE browsers. Linux support is in the works via the Moonlight project from Mono.
This work is licensed under a Creative Commons Attribution-Share Alike 2.0 License.