Calling a C# Library from Python

How to call a C# code from python

The short answer would be

os.system("myapp.exe")

How to load a C# dll in python?

This is to answer the second part of your Question
Try making the DLL COM visible.

by using the

[ComVisible(true)]

Ok IronPython is a .net implemenatation of the Python language
The technology is going to use the DLR of the .net 4.0 when it arrives so IronPython will have more Dynamism (is that a word).
(In english if you're a Python guru, you'll feel more at home when you use IronPython)

So you may well choose IronPython, if you do that you can skip the COM visible part. Since both (C# , Iron Python) are under .Net

http://ironpython.net/

Calling C# code from python using pythonnet

I should admit that pythonnet is not supposed to crash CPython interpreter even on this bad example of generic call with invalid arguments to the method.

Here is how to properly make your generic calls with pythonnet, notice how passing wrong types fails properly:

In [3]: NonGenericClass.GenericMethod[Person](TempGenericClass[Person]())

In [4]: NonGenericClass.GenericMethod[Employee](TempGenericClass[Employee]())

In [5]: NonGenericClass.GenericMethod[Person](TempGenericClass[Employee]())
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-d13751f7586f> in <module>()
----> 1 NonGenericClass.GenericMethod[Person](TempGenericClass[Employee]())

TypeError: No method matches given arguments

In [6]: NonGenericClass.GenericMethod[Employee](TempGenericClass[Person]())
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-6-04c3c0db6c6b> in <module>()
----> 1 NonGenericClass.GenericMethod[Employee](TempGenericClass[Person]())

TypeError: No method matches given arguments


Related Topics



Leave a reply



Submit