how to call python code from C#

P

paritosh mahana

Hi all,
How can I call python code from my C# code. One thing is to make an
..exe file of the python program and then try to call it from my C#
code. But I don't like that idea. Is there any other way to do this.
Like making a .dll file from the python code and somehow call it from
C# program.But I couldn't find anything on this topic on the net.
Actually my GUI is in C# and rest part is in python, and i need to
call python from my C# program. Please correct me if I am wrong
anywhere.
thanks
paritosh.
 
P

Peter Hansen

paritosh said:
How can I call python code from my C# code. One thing is to make an
.exe file of the python program and then try to call it from my C#
code. But I don't like that idea. Is there any other way to do this.
Like making a .dll file from the python code and somehow call it from
C# program.But I couldn't find anything on this topic on the net.
Actually my GUI is in C# and rest part is in python, and i need to
call python from my C# program. Please correct me if I am wrong
anywhere.

You could use ctypes or the pywin32 package to provide your
Python code with an ActiveX interface. Then you could just
use it via COM, like any other COM object. Lots of references
available via Google if you want to learn more about this
approach...

-Peter
 
D

Dave Brueck

Peter said:
paritosh said:
How can I call python code from my C# code.
[snip]
You could use ctypes or the pywin32 package to provide your
Python code with an ActiveX interface. Then you could just
use it via COM, like any other COM object. Lots of references
available via Google if you want to learn more about this
approach...

Lemme add my two cents and say that this approach works well.

We have a component that uses ctypes and runs as a COM local server (its own
..exe) and we currently use it both from Internet Explorer and from a C#
application. COM can be hairy initially, but if you have any experience with COM
then this approach is pretty straightforward.

-Dave
 
J

just starting

Thanks for all your kind information. I haven't used COM objects so
far.I think now I have to learn it.Anyway thanks a lot again.
paritosh.


Peter said:
paritosh said:
How can I call python code from my C# code.
[snip]
You could use ctypes or the pywin32 package to provide your
Python code with an ActiveX interface. Then you could just
use it via COM, like any other COM object. Lots of references
available via Google if you want to learn more about this
approach...

Lemme add my two cents and say that this approach works well.

We have a component that uses ctypes and runs as a COM local server (its own
.exe) and we currently use it both from Internet Explorer and from a C#
application. COM can be hairy initially, but if you have any experience with COM
then this approach is pretty straightforward.

-Dave
 
R

Ryan Paul

Hi all,
How can I call python code from my C# code. One thing is to make an
.exe file of the python program and then try to call it from my C#
code. But I don't like that idea. Is there any other way to do this.
Like making a .dll file from the python code and somehow call it from
C# program.But I couldn't find anything on this topic on the net.
Actually my GUI is in C# and rest part is in python, and i need to
call python from my C# program. Please correct me if I am wrong
anywhere.
thanks
paritosh.

This may not be relevant, but if what you are looking for is a way to
write a program for .NET with a language that doesnt suck, you might want
to look at Boo (http://boo.codehaus.org/). I'm not sure if it can directly
use winforms, but you can probably make native .net libraries with it that
you can utilize from C#. Boo looks and feels almost exactly like
Python, so the learning curve is minimal, and using it is very pleasant.

-- SegPhault
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,218
Messages
2,571,123
Members
47,725
Latest member
Rudy

Latest Threads

Top