Python Forum
calling python function with multiple argument in C#
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
calling python function with multiple argument in C#
#1
Hello All,

I am stuck with a new problem . I have created a simple python code say for summing 2 variables. File is called as Addition.py
Addition.py
import sys
import math
def ad(a,b):
    print(a+b)
Now I am trying to run Additional.py file with a c# application with below mentioned code. I have tried to pass 2 argument for addiing value but still in myString variable i get null value. I do not get any error or any exception while executing code. Wall Wall
public void finalMethod()
        {
            string pyt = @"C:\Python34\python.exe";
            int x = 2;
            int y = 5;
            
            string myPyt = @"D:\Addition.py"; 
            ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(pyt);

            myProcessStartInfo.UseShellExecute = false;
            myProcessStartInfo.RedirectStandardOutput = true;

            myProcessStartInfo.Arguments = myPyt + " " + x + " " + y;
            
            Process myProcess = new Process();
            myProcess.StartInfo = myProcessStartInfo;
            
            myProcess.Start();

            StreamReader myStreamReader = myProcess.StandardOutput;
            string myString = myStreamReader.ReadLine();

            myProcess.WaitForExit();
            myProcess.Close();

            lblText.Content = myString;
        }
My purpose is simple that my main code is written in C# but i have lot of math formulas which i want to write in pyhton and than want to call those function based on process requirement.
Can anyone please help

thanks
Reply
#2
As this question requires knowledge of C#, this question is better asked on a C# forum.
However, Someone with C# experience may reply
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python script is hanging while calling a procedure in database prasanthi417 4 521 Jan-17-2024, 02:33 PM
Last Post: deanhystad
  __init__() got multiple values for argument 'schema' dawid294 4 2,371 Jan-03-2024, 09:42 AM
Last Post: buran
  mutable argument in function definition akbarza 1 483 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  python convert multiple files to multiple lists MCL169 6 1,557 Nov-25-2023, 05:31 AM
Last Post: Iqratech
  calling external function with arguments Wimpy_Wellington 7 1,446 Jul-05-2023, 06:33 PM
Last Post: deanhystad
  Calling a function (which accesses a library) from another file mouse9095 4 823 Jun-07-2023, 08:55 PM
Last Post: deanhystad
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,095 Dec-25-2022, 03:00 PM
Last Post: askfriends
  i want to use type= as a function/method keyword argument Skaperen 9 1,863 Nov-06-2022, 04:28 AM
Last Post: Skaperen
  PyRun_SimpleFile calling multiprocessing Python Class cause endless init loop Xeno 2 1,049 Sep-19-2022, 02:32 AM
Last Post: Xeno
Sad Iterate randint() multiple times when calling a function Jake123 2 2,056 Feb-15-2022, 10:56 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020