3

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

10
  • 1
    You may want to search for a tool called Iron Python Commented Mar 7, 2016 at 16:06
  • 1
    I haven't personally done this, but this looks pretty legit: codeproject.com/Articles/657698/… Commented Mar 7, 2016 at 16:07
  • 3
    Possible duplicate of run a python script from c# Commented Mar 7, 2016 at 16:21
  • IronPython is for using Python on the CLR, meaning you can use existing C# code/libraries in python, not the other way around. If you want to execute a python script from C# check the question linked by @MarkyPython Commented Mar 7, 2016 at 16:21
  • @Sidewinder94 IronPython works both ways: I know from experience it will let a C# app run python, having used to allow users to enter Python code instead of having to parse mathematical expressions. Commented Mar 9, 2016 at 16:57

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

ironpython should definitely be higher in preference than calling python via Processes. Especially if you want to return anything more than just a number or string.
Thanks all for the wonderful help and discussion! Iron Python will get the job done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.