Discussion:
[Python.NET] using c# method from python
munawwarah Chamroo
2010-02-18 09:34:11 UTC
Permalink
Hi,
I am currently developing an application where i need to call some c#
methods from my python code.
I want to know if this is possible to do using pythonnet and how to do it.

for example i have a c# class foo and in foo i have a method bar()
Now i need to call method bar() in my python code.
How should i do this.

Please help
Tribble, Brett
2010-02-18 19:22:27 UTC
Permalink
Depending on how you're code works in C#, the way you access it from Python may vary, but the basic approach is:

Compile your code as a .dll assembly, then from Python do:

import clr # Imports the pythonnet clr stuff
clr.AddReference("myAssembly.dll")
myObjectHandle = myAssembly.myClass()
myObjectHandle.bar()



From: pythondotnet-bounces+btribble=ea.com-+ZN9ApsXKcEdnm+***@public.gmane.org [mailto:pythondotnet-bounces+btribble=ea.com-+ZN9ApsXKcEdnm+***@public.gmane.org] On Behalf Of munawwarah Chamroo
Sent: Thursday, February 18, 2010 1:34 AM
To: pythondotnet-+ZN9ApsXKcEdnm+***@public.gmane.org
Subject: [Python.NET] using c# method from python

Hi,
I am currently developing an application where i need to call some c# methods from my python code.
I want to know if this is possible to do using pythonnet and how to do it.

for example i have a c# class foo and in foo i have a method bar()
Now i need to call method bar() in my python code.
How should i do this.

Please help

Loading...