尝试读取2个文件并在python脚本中作为参数发送。PythonScript会将这两个文件字符串串联在一起

我尝试了很少的代码,但并没有帮助我。 我编写的C#代码如下所示,其中我从两个文件中获取数据(每个文件包含2000多个单词),并尝试格式化arg1和arg2字符串中的数据,以便它可以从每个文件中提取多行并用作一个串。但是在Python脚本中,它并没有串联这些参数。

     System.Diagnostics.ProcessStartInfo start = new System.Diagnostics.ProcessStartInfo();
        protected void Page_Load(object sender,EventArgs e)

         {

        start.FileName = @”C:\Users\vinita.singh\AppData\Local\Programs\Python\Python37-32\python.exe”; 

        string file1 = System.IO.File.ReadAllText(@”C:\Users\Priyank\Desktop\Python Files\File1.txt”);

        string file2 = System.IO.File.ReadAllText(@”C:\Users\Priyank\Desktop\Python Files\File2.txt”);

        string arg1 = $@”{‘”’}” + file1 + $”{’”’}”;

        string arg2 = $@”{’”’}” + file2 + $”{’”’}”;

        *//Python Code* 

        start.Arguments = string.Format(“{0} {1} {2} “,Path.Combine(AppDomain.CurrentDomain.BaseDirectory,“CalculateString.py”),arg1,arg2);

        start.UseShellExecute = false;// Do not use OS shell

        start.CreateNoWindow = true; // We don’t need new window

        start.RedirectStandardOutput = true;// Any output,generated by application will be redirected back 

        start.RedirectStandardError = true;// Any error in standard output will be redirected back (for example exceptions) 

        start.LoadUserProfile = true; using (System.Diagnostics.Process process = System.Diagnostics.Process.Start(start))
        {
        using (StreamReader reader = process.StandardOutput)
        {
        string stderr = process.StandardError.ReadToEnd(); // Here are the exceptions from our Python script 

        string result = reader.ReadToEnd(); // Here is the result of StdOut(for example: print “test”) 

        lblinfo.Text = “From System Diagnostics : “;

        Results.Text = result;
        }
        }
        }

Python脚本将这两个参数串联起来,如下所示:

    import sys

        class CalculateString:

        def add(self,x,y):

        return x+y

        #creating object of class

        calculatorObj = CalculateString()

        *#capturing input from command line and casting to string*

        x = sys.argv[1]

        y = sys.argv[2]

        #z =sys.argv[3]

        z = calculatorObj.add(x,y)

wendy6923 回答:尝试读取2个文件并在python脚本中作为参数发送。PythonScript会将这两个文件字符串串联在一起

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3038543.html

大家都在问