Calling C# COM (.NET) from python

Mike Driscoll kyosohma at gmail.com
Mon Dec 8 12:19:15 EST 2008


On Dec 8, 10:53 am, Andrew Falanga <af300... at gmail.com> wrote:
> Hi,
>
> I've never programmed in python and only have a small understanding of
> what is wrapped up in the terms COM and .NET.  Is there a way of using
> python to get a hold of objects written in C# as COM objects using
> python?  I'm looking for ways to avoid VBScript (which, after a couple
> of weeks, I've determined to be horrid).  That is, is there a way of
> getting at COM objects in python that's similar to doing a
> CreateObject call in VBScript (http://msdn.microsoft.com/en-us/library/
> dcw63t7z.aspx)?
>
> Thanks,
> Andy

You're probably looking for the PyWin32 package (AKA: Python for
Windows extensions). It's an external package for Python created
mainly by Mark Hammond. You can find it here: http://sourceforge.net/projects/pywin32/

It's a loose wrapper to the win32 bindings. It has a win32com module
in it. You can usually take some VB type code and tweak it slightly to
work with Python. There's some docs here:

http://docs.activestate.com/activepython/2.4/pywin32/win32_modules.html

You may also be able to use ctypes. Regardless, the PyWin32 package
has a great mailing list with helpful people that I highly recommend:
http://mail.python.org/mailman/listinfo/python-win32

Other than that, you have the option of using IronPython which can
actually import .NET modules itself. I've messed with it a little, but
I'm not fluent enough in .NET to be able to use a lot of its
capabilities. Regardless, you should read up on it as it offers lots
of interesting capabilities:

http://www.codeplex.com/IronPython

Mike



More information about the Python-list mailing list