tags:

views:

194

answers:

3

I have a Python module with nothing but regular global functions. I need to call it from another business-domain scripting environment that can only call out to C DLLs. Is there anyway to build my Python modules so that to other code it can be called like a standard C function that's exported from a DLL? This is for a Windows environment. I'm aware of IronPython, but as far as I know it can only build .NET Assemblies, which are not callable as C DLL functions.

+5  A: 

Take a look at this Codeproject article. One way would be wrap your python functions in a C dll and expose this to the callee.

COM is a binary protocol to solve this issue. But you will have to wrap this python dll in a COM wrapper. And add some code on the calling side as well.

dirkgently
+3  A: 

The standard solution is to embed the Python interpreter (which is already a C DLL) in your application.

http://www.python.org/doc/2.5.2/ext/win-dlls.html

http://docs.python.org/extending/embedding.html

S.Lott
+1: the simplest way
J.F. Sebastian
+2  A: 

Py2exe can generate COM dlls from python code, by compiling and embedding python code + interpreter. It does not, AFAIK, support regular DLLs yet. For that, see dirkgently's answer about embedding python yourself.

Marcus Lindblom