Posts

Showing posts from August, 2007

Load .NET Assembly Using Python

To load .NET assemblies via Python you should use Python.NET. I choose Python.NET over IronPython, because IronPython seems less compatible with standard Python libraries (amongst other things). Once you've downloaded and installed Python.NET (http://pythonnet.sourceforge.net/), you can begin the integration. Integration Code Sample: [code] import sys # import Python.NET module(s) import CLR from CLR.System.Reflection import Assembly # get the root path (for the dlls) pythonLoc = sys.path[0] pythonLoc = pythonLoc[0:pythonLoc.rindex("\\")+1] for dllName in ["MyDLL.dll", "Microsoft.Practices.EnterpriseLibrary.Common.dll", "Microsoft.Practices.EnterpriseLibrary.Data.dll"]:    Assembly.LoadFile(pythonLoc+dllName) # end for # create instance of .NET class csharpClass = clr.MyDLL.MyCsharpClass() # call member of .NET class result = csharpClass.SomeMethod() [/code] As you can see the key here is to use absolute paths. The variable 

wxPython with Python .NET intergration

Image
To use wxPython and Python.NET together is a simple task. Luckily Python.NET is an interpreter and wxPython are modules. This will allow you to utilize wxPython and the .NET framework all from Python. Its a Win32 Python programmer's dream, leverage .NET assemblies, wxWidgets UI, and Python! 1.) Download wxPython (http://www.wxpython.org/download.php) & Python.NET (http://pythonnet.sourceforge.net/) 2.) Install Python.NET (and remember the install directory) 3.) Install wxPython in the same directory you installed Python.NET Notes: To access PyCrust (interactive wxPython shell), go to 'C:\PythonNet\Lib\site-packages\wx-2.8-msw-unicode\wx\py\pycrust.py' To access XRCed (XRC editor), go to 'C:\PythonNet\Lib\site-packages\wx-2.8-msw-unicode\wx\tools\XRCed\xrced.py'