我想将多个字符串变量从我的程序 C# 传递给 Python 脚本。
这是我在 C# 中的函数,我在其中调用文件 InsertSemantic.py,我想在那里传递 9 个参数(nome、formVerb、contesto ecc ...)
private void insertDatabase(String nome, String formVerb, String contesto, String sinonimi, String significato, String class_gramm, String class_prag, String class_sem, String retorico)
{
string arg = string.Format(@"C:\Users\marco\eclipse-workspace\my_project\src\InsertSemantic.py {0}", nome, formVerb, contesto, sinonimi, significato, class_gramm, class_prag, class_sem, retorico);
try
{
Process p1 = new Process();
p1.StartInfo = new ProcessStartInfo(@"C:\Python27\python.exe", arg);
p1.StartInfo.UseShellExecute = false;
p1.StartInfo.RedirectStandardOutput = true;
p1.Start();
p1.WaitForExit();
}
catch (Exception ex)
{
Console.WriteLine("There is a problem in your Python code: " + ex.Message);
}
Console.WriteLine("Press enter to exit...");
Console.ReadLine();
}
我在 InsertSemantic.py 中写了这一行:
import sys
nome= sys.argv[1]
formVer=sys.argv[2]
contesto= sys.argv[3]
sinonimi=sys.argv[4]
significato=sys.argv[5]
gramm=sys.argv[6]
prag=sys.argv[7]
sem=sys.argv[8]
retorico=sys.argv[9]
但是通过一个简单的打印,我看到我只收到一个参数(nome)而另一个参数没有通过......有人可以帮助我吗?