473,732 Members | 2,205 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to call python code from C#

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.
Jul 18 '05 #1
4 5673
paritosh mahana wrote:
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
Jul 18 '05 #2
Peter Hansen wrote:
paritosh mahana wrote:
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
Jul 18 '05 #3
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.
On Mon, 24 Jan 2005 12:43:50 -0700, Dave Brueck
<da**@pythonapo crypha.com> wrote:
Peter Hansen wrote:
paritosh mahana wrote:
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
--
http://mail.python.org/mailman/listinfo/python-list

Jul 18 '05 #4
On Tue, 25 Jan 2005 00:35:04 +0530, paritosh mahana wrote:
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
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
48763
by: Tubby Tudor | last post by:
What is the best way to call one python script from within another python script? For example: one.py finishes succesfully and calls two.py which finishes OK and then calls three.py Thanks guys!
6
22334
by: Dave Kuhlman | last post by:
Is JPE (the Python Java Extension) being used widely/actively? I tried to build it (with Python 2.3.4, j2se 1.4 on Debian GNU/Linux) and had quite a bit of trouble. And, then, the samples did not run. Is there another way to call Java code from Python? The JPE project does not seem too active lately, or is it?
2
3001
by: FAN | last post by:
I want to define some function in python script dynamicly and call them later, but I get some problem. I have tried the following: ################################## # code ################################## class test: def __init__(self): exec("def dfunc(msg):\n\tprint msg\nprint 'exec def function'") dfunc('Msg in init ...') # it work
4
2429
by: Nicolas Vigier | last post by:
Hello, I have in my python script a function that look like this : def my_function(arg1, arg2, opt1=0, opt2=1, opt3=42): if type(arg1) is ListType: for a in arg1: my_function(a, arg2, opt1=opt1, opt2=opt2, opt3=opt3) return if type(arg2) is ListType:
0
1256
by: haynes george | last post by:
hi .. I was reading the tutorial "Extending and Embedding the python interpreter" available with python .. http://www.python.org/doc/2.2.3/ext/ext.html As per given in the tutorial i created an interface to the system() system call.
3
3736
by: evelyne0510 | last post by:
Hi all, I have created a XML-RPC model (with server and client) written in Java. I want to call the methods in another XML-RPC model written in Python. I know that in Java, I can use like "xmlrpc_client.excute("handler_name.method", param)" to call the methods in my xml-rpc server written in java. But how can I call the methods in Python? I cannot creat a handler in my Python XML-RPC server.....
2
2320
by: bappai | last post by:
Hello, I am trying to actually call a GUI from my C++ code which would have buttons and therefore can call functions from C++ again, ie extend the C++ code also. I am faced with a peculiar problem. I actually tried out an embedding code (downloaded from the net) which actually calls any function which has a text display but when I try to call any code which opens cleanly in python prompt it crashes. To make matters more concrete let me...
2
2894
by: The Pythonista | last post by:
Yesterday, I was hacking around a bit, trying to figure out how to implement the semantics of call/cc in Python. Specifically, I wanted to translate this Scheme code to equivalent Python: #### (define theContinuation #f) (define (test) (let ((i 0))
275
12337
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9447
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9307
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9181
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.