Calling C# COM (.NET) from python

Discussion in 'Python' started by Andrew Falanga, Dec 8, 2008.

  1. 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
    Andrew Falanga, Dec 8, 2008
    #1
    1. Advertising

  2. Andrew Falanga

    Ben Kaplan Guest

    On Dec 8, 2008, at 11:53 AM, Andrew Falanga <> 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
    > --
    > http://mail.python.org/mailman/listinfo/python-list


    I would not deal with COM at all. I personally have not used it, but
    there is a version of python called IronPython that's written in C#,
    so it can use .NET and, I think, other C# objects. Other people will
    probably help you more, but you might want to look into that and maybe
    ask this on the python-win list.
    Ben Kaplan, Dec 8, 2008
    #2
    1. Advertising

  3. On Dec 8, 10:53 am, Andrew Falanga <> 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
    Mike Driscoll, Dec 8, 2008
    #3
  4. On Dec 8, 11:14 am, Ben Kaplan <> wrote:
    > On Dec 8, 2008, at 11:53 AM, Andrew Falanga <> 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
    > > --
    > >http://mail.python.org/mailman/listinfo/python-list

    >
    > I would not deal with COM at all. I personally have not used it, but  
    > there is a version of python called IronPython that's written in C#,  
    > so it can use .NET and, I think, other C# objects. Other people will  
    > probably help you more, but you might want to look into that and maybe  
    > ask this on the python-win list.


    As I understand it, IronPython can use anything done in the CLR, so
    technically I could write something in VB.NET, C# or any of the other
    VS languages and then use them from within IronPython. It should be
    noted that IronPython does not support most 3rd party packages that
    are not pure python. As I recall, it doesn't have the complete builtin
    library either, but it's close.

    Reads the docs and check it out at least. If you already know .NET
    languages, then you'll probably find IronPython helpful.

    Mike
    Mike Driscoll, Dec 8, 2008
    #4
  5. On Dec 8, 11:52 am, Mike Driscoll <> wrote:
    > On Dec 8, 11:14 am, Ben Kaplan <> wrote:
    >
    >
    >
    > > On Dec 8, 2008, at 11:53 AM, Andrew Falanga <> 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
    > > > --
    > > >http://mail.python.org/mailman/listinfo/python-list

    >
    > > I would not deal with COM at all. I personally have not used it, but  
    > > there is a version of python called IronPython that's written in C#,  
    > > so it can use .NET and, I think, other C# objects. Other people will  
    > > probably help you more, but you might want to look into that and maybe  
    > > ask this on the python-win list.

    >
    > As I understand it, IronPython can use anything done in the CLR, so
    > technically I could write something in VB.NET, C# or any of the other
    > VS languages and then use them from within IronPython. It should be
    > noted that IronPython does not support most 3rd party packages that
    > are not pure python. As I recall, it doesn't have the complete builtin
    > library either, but it's close.
    >
    > Reads the docs and check it out at least. If you already know .NET
    > languages, then you'll probably find IronPython helpful.
    >
    > Mike


    To all, thanks for the great replies. I've got something to work with
    here. Thanks to for the link to PyWin32 and the mailing list. That
    sounds promising as does this IronPython. I wished I knew more
    of .NET and python more (as my original post claims, I've never
    written Python and I only wished I knew the .NET stuff better for
    better footing in this). I'm very much the proverbial, "fish out of
    water," as I'm a UNIX man now stuck in a Windows world.

    Thanks again,
    Andy
    Andrew Falanga, Dec 8, 2008
    #5
  6. On Dec 8, 3:33 pm, Andrew Falanga <> wrote:
    > On Dec 8, 11:52 am, Mike Driscoll <> wrote:
    >
    >
    >
    > > On Dec 8, 11:14 am, Ben Kaplan <> wrote:

    >
    > > > On Dec 8, 2008, at 11:53 AM, Andrew Falanga <> 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
    > > > > --
    > > > >http://mail.python.org/mailman/listinfo/python-list

    >
    > > > I would not deal with COM at all. I personally have not used it, but  
    > > > there is a version of python called IronPython that's written in C#,  
    > > > so it can use .NET and, I think, other C# objects. Other people will  
    > > > probably help you more, but you might want to look into that and maybe  
    > > > ask this on the python-win list.

    >
    > > As I understand it, IronPython can use anything done in the CLR, so
    > > technically I could write something in VB.NET, C# or any of the other
    > > VS languages and then use them from within IronPython. It should be
    > > noted that IronPython does not support most 3rd party packages that
    > > are not pure python. As I recall, it doesn't have the complete builtin
    > > library either, but it's close.

    >
    > > Reads the docs and check it out at least. If you already know .NET
    > > languages, then you'll probably find IronPython helpful.

    >
    > > Mike

    >
    > To all, thanks for the great replies.  I've got something to work with
    > here.  Thanks to for the link to PyWin32 and the mailing list.  That
    > sounds promising as does this IronPython.  I wished I knew more
    > of .NET and python more (as my original post claims, I've never
    > written Python and I only wished I knew the .NET stuff better for
    > better footing in this).  I'm very much the proverbial, "fish out of
    > water," as I'm a UNIX man now stuck in a Windows world.
    >
    > Thanks again,
    > Andy


    Andy,

    Welcome to the wonderful world of Python programming. It's fun and
    cool! Windows is a complex place, but the Python crew on that PyWin32
    mailing list will help you out with that stuff and the people here
    will help you with your more general questions.

    Last week, there was another beginner who needed some clues for where
    to go for learning the language. I suggest you read that thread as it
    had lots of good examples:

    http://groups.google.com/group/comp.lang.python/browse_frm/thread/29278b3db85a1341#

    I recommend the Dive Into Python online book too, which is listed in
    the link above. There are also lots of quality physical books out
    there. Let me know if you need any suggestions for those.

    Have a nice day!

    Mike
    Mike Driscoll, Dec 8, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Ternier
    Replies:
    4
    Views:
    3,969
    Cowboy \(Gregory A. Beamer\) [MVP]
    Jul 29, 2004
  2. =?Utf-8?B?TWFydGluIExlZQ==?=

    Calling FormsAuthentication.SignOut() after calling Response.Flush

    =?Utf-8?B?TWFydGluIExlZQ==?=, Sep 28, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    732
    =?Utf-8?B?RXRoZW0gQXp1bg==?=
    Sep 28, 2004
  3. Andreas Lagemann
    Replies:
    8
    Views:
    477
    Mike Wahler
    Jan 10, 2005
  4. tiwy
    Replies:
    0
    Views:
    438
  5. Klaus Friese

    c++ calling java calling c++ ...

    Klaus Friese, Aug 12, 2005, in forum: C++
    Replies:
    7
    Views:
    579
    Roland Pibinger
    Aug 15, 2005
Loading...

Share This Page