[Python.NET] bridging C# and Python

Matt Mackowski matt.mackowski at slipg8.com
Tue Nov 27 20:20:55 CET 2007



I would like to run a python application have it call a C# application
and have the two applications be able to call functions in the other

I have gotten the python to open and run the C# application and I am
able to run any function from the C# app in python.  


What I am having trouble with is calling python functions from the C#
when the C# app was started by a python call.  When I run the C# alone I
can call the python functions.


Part of my problem I think is that the C# app doesn't know where to fine
the python modules.  Where do they need to be if I want to use the


In python my codes looks like this 


import clr  

import pythoncom


from ScriptEditor import ScriptEditor

self.app = ScriptEditor()


from System.Windows.Forms import Application



ScriptEditor is my C# app. 

I can call most of the C# functions from python with the above code.
The C# functions I cannot call are ones that use python for example



        public void usingPython()




            IntPtr pyLock = PythonEngine.AcquireLock();

            PyObject pyObj =  PythonEngine.ImportModule("hello");


            pyObj.InvokeMethod("helloCallback", new PyTuple());






That doesn't work. It works when I call the function in C#.

Hello.py looks like this:


def hello():

    return 'hello'


def helloCallback():

      print "This is a Test and Of The python.net"





-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/pythondotnet/attachments/20071127/1d9b878c/attachment.htm 

More information about the PythonDotNet mailing list