Using C# code in IronPython
I'm about to undertake a .NET project: We need to create a create a program that utilize some existing C# code, and I'm hoping to use IronPython. (I'm an experienced Python programmer, but a bit of a .NET newbie).
My question is: Is IronPython a good fit for using mostly C# code, or would it be better just to use C#? If IronPython is 开发者_开发技巧a good fit, are there any pitfalls to look out for?
You'll need to compile the C# code into an assembly (DLL) you can use within IronPython. Once you do this, IronPython can use this just like any other .NET assembly.
This is a common usage scenario for IronPython.
If you are in a Windows environment for reasons beyond your control, there are a lot of advantages in using IronPython.
Its just like Python, only .NET. Once you learn the idosyncratic elements of how to reference an assembly, how to instantiate objects, browse objects, etc. it is really nice.
You don't need Visual Studio to develop. Notepad++ or any decent text editor is all you need. If you really must have an IDE you can go with SharpDevelop. Now if you have VS2010, the new plugin for Ironpython is nice and should get better with future releases.
With the introduction of Ironpython 2.7 and .NET 4.0, the startup time issues of previous versions have been mostly negated.
I find the WPF and XAML approach much much easier than wx for creating GUI applications.
Ironpython scripts can be compiled into exe's for easy distribution
That said, there are downsides.
Most packages do not install directly into Ironpython, forcing you to install into CPython, then copying over the relevant modules.
Python extension that utilize pyd shared libraries don't work unless you use Ironclad, and even then you can have issues.
You give up being cross platform, unless your users are running Mono and even then you lose some of the cool features like WPF.
You are a bit behind the development curve. Ironpython is currently at 2.7 Beta 1 and has been since October, when Microsoft released the code into the wild. Prior to that no one outside of MS could submit patches. The community leadership is on track for a 2.7 RTM release in February and then starting the 3.x development.
精彩评论