Iron Python: How to talk to the .NET Framework

Iron Python is an implementation of the Python programming language that runs on the Common Language Runtime and can use the classes of the .NET Framework.

Here are some quick notes on how to interface with the framework from Iron Python:

  1. Open the Iron Python REPL.
  2. Import the clr module.
  3. Add a reference to the .NET Namespaces you want to interact with.
  4. Start using the .NET classes as if they were Python classes.

Below I transcribed a little code snippet for you to use as an example. I also provide a screen capture of the sample and the outcome of running it.

 import clr
 from System.Windows.Forms import Application, Form, Button, MessageBox

 f = Form()
 b = Button()

 f.Text = "Hello World!"
 b.Text = "Click Me!"

 def clicked(sender, args):
     MessageBox.Show("Hello, Again...")

 b.Click += clicked

Iron Python



Comments powered by Disqus