Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running several python scripts from C#

I am hoping that someone might be able to help me out here. I am relatively new to C# and am trying to execute some Python code I wrote from within a C# winform app.

What I would like to do is input a name from a text box within the winform and have it process through the python scripts and return a result in another textbox on the winform.

I have found several good examples of how to execute a single script within C#, but I am having some trouble understanding how I can reference multiple scripts.

As an example, I have one python script that references two other scripts within code

from FindTelephone import *
from FindAddress import *

def createPerson(name)
  telephone = FindTelephone(name)
  address = FindAddress(name)
....

Is there a way to have C# point to a reference of my other python scripts before running my main script?

Thanks in advance for the help.

Marshall

like image 294
MarshallTrufant Avatar asked Feb 07 '26 18:02

MarshallTrufant


1 Answers

Like in these posts?: Call Python function from c# (.NET), run a python script from c#?

Or

You might want to look into pythonnet.

Or

If you want an easyer way of doing this then I recommend using Iron Python in place of normal Python. IronPython is an open-source implementation of the Python programming language which is tightly integrated with the .NET Framework. Means that it is much easyer to use with C# and Windows Forms and looks almost just like normal Python.

Or

For in case you are using Visual Studio, VS has some Python tools that might help you in your quest. Link. You can find more documentation Here This last link is provided by Jedediah from comments so vote his comment up if you liked this last link.

Other handy link: Integrating Python With Other Languages

like image 126
Morganis Avatar answered Feb 09 '26 10:02

Morganis