{"id":96,"date":"2008-12-03T03:36:56","date_gmt":"2008-12-03T00:36:56","guid":{"rendered":"http:\/\/www.held.org.il\/blog\/?p=96"},"modified":"2008-12-03T03:36:56","modified_gmt":"2008-12-03T00:36:56","slug":"few-ironpython-impressions-and-a-quick-guide","status":"publish","type":"post","link":"http:\/\/www.held.org.il\/blog\/2008\/12\/few-ironpython-impressions-and-a-quick-guide\/","title":{"rendered":"Few IronPython impressions and a quick guide"},"content":{"rendered":"<p>I've been messing with <a href=\"http:\/\/www.codeplex.com\/Wiki\/View.aspx?ProjectName=IronPython\">IronPython<\/a> 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 \ud83d\ude42<\/p>\n<p>What is it good for? Well, accessing the whole .NET framework with Python code is quite a strong feature. <a href=\"http:\/\/code.google.com\/p\/ironclad\/\">IronClad<\/a> project aims to allow accessing CPython (the popular implementation) binary modules, not sure how mature it is.<\/p>\n<p>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.<\/p>\n<p>And now to few specific notes, that a CPython user might need as of version 2.0RC2:<\/p>\n<p><strong>Loading .NET assemblies howto<br \/>\n<\/strong><\/p>\n<pre>import clr\nclr.AddReference(\"mscorlib\")\nclr.AddReference(\"System.Drawing\")\nimport Microsoft.Win32\nimport System.Drawing<\/pre>\n<p>note that <em>mscorlib<\/em> is needed for many common namespaces, such as <em>Microsoft.Win32<\/em>. In MSDN, the \"assembly name\" is specified for each namespace, so it's easy to find out.<\/p>\n<p><strong>Python logging module bug<\/strong><\/p>\n<p>The famous <em>logging<\/em> module currently throws an exception instead of printing lines. Here's a workaround till they fix it:<\/p>\n<pre>import logging\nlogging._srcfile = None\n<\/pre>\n<p>[see Michael's comment below]<br \/>\n<strong>_winreg module problem with REG_BINARY type<\/strong><\/p>\n<p>The CPython _winreg implementation works fine, however in IronPython there's currently a little problem: \"high ascii\" (&gt;128) chars are getting screwed because of some converting\/encoding problem (uses <em>System.Text.Encoding.ASCII<\/em> which is 7bit aware). My workaround was to use directly the <em>Microsoft.Win32.Registry<\/em> 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.<\/p>\n<p><strong>Compiling to DLL\/EXE<\/strong><\/p>\n<p>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 \"<a href=\"http:\/\/www.codeplex.com\/IronPython\/Release\/ProjectReleases.aspx?ReleaseId=14353\">IronPython 2 Beta 4<\/a>\" release.<\/p>\n<p>Note: sometimes EXEs don't behave exactly the same as in the interpreter:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.codeplex.com\/IronPython\/Release\/ProjectReleases.aspx?ReleaseId=14353\">sys.argv bug<\/a>: would probably be fixed soon<\/li>\n<li>\"clr.AddReference()\" lines are sometimes (always?) not needed when using the interpreter, but are always required in EXE.<\/li>\n<\/ul>\n<p>I find a \"make\" system pretty needed for IronPython.<\/p>\n<p><strong>Writing GUI<\/strong><\/p>\n<p>Windows.Forms is an integral part on .NET, and as such, is native to IronPython. <a href=\"http:\/\/www.codeplex.com\/IronPythonStudio\">IronPython Studio<\/a> 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.<\/p>\n<p>-------<\/p>\n<p>Debugging tools: haven't checked that area yet.<\/p>\n<p>Sleep now.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been messing with IronPython lately. It&#8217;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 \ud83d\ude42 What is it good for? Well, accessing the whole .NET [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[200,93,201],"_links":{"self":[{"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/posts\/96"}],"collection":[{"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/comments?post=96"}],"version-history":[{"count":0,"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/posts\/96\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/media?parent=96"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/categories?post=96"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/tags?post=96"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}