Portrait of Edd Dumbill, taken by Giles Turnbull

Subscribe to updates

Feed icon Atom or RSS

or get email updates

What I make

expectnation
a conference management web application


XTech Conference
a European web technology conference

Setting properties at construct-time in IronPython

Here's a common pattern when working in C#. You create an object then set several of its properties:

  foo = new Foo (arg1, arg2);
  foo.ThisProperty = whatever;
  foo.ThatProperty = anothervalue;

IronPython does a nice thing when reflecting .NET classes into Python, it allows keyword arguments in the constructor to be used for property assignments. Here's a real life example from Gtk#. First, the old:

  l = Gtk.Label ("_First name:")
  l.Xalign = 0
  l.MnemonicWidget = first_entry

And the new:

  l = Gtk.Label ("_First name:", Xalign = 0, MnemonicWidget = first_entry)

Very cool.

blog comments powered by Disqus


You are reading the weblog of Edd Dumbill, writer, programmer, entrepreneur and free software advocate.
Copyright © 2000-2012 Edd Dumbill