从C#传递python脚本中的参数 [英] Passing parameter in python script from C#

查看:556
本文介绍了从C#传递python脚本中的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用Ironpython和C#



我在下面写了代码来访问测试.py脚本文件,它将处理输入并返回输出。但我不知道怎样才能传递参数呢?



任何熟悉C#,Ironpython的人,请回复。





Hi,

I am using Ironpython with C#

I wrote below code to access test.py script file which will process the input and return the output. But I don't know how can I pass the parameter in it?

Anyone familiar with C#, Ironpython, kindly respond.


ScriptEngine pyEngine = Python.CreateEngine();
                int _ans = pyEngine.Execute(@"test.py");

推荐答案

你好阿苏,



请查看这个 [ ^ ]教程。



基本上你需要使用 createScope 方法来创建脚本运行的范围,然后设置变量( scope.SetVariable(Key,Value) )要传递给它中的脚本。脚本可以使用setVariable调用中指定的键来引用这些变量。



问候,
Hello Ashu,

Please have a look at this[^] tutorial.

Basically you need to use createScope method to create the scope within which the script is going to run and then set the variables (scope.SetVariable(Key, Value)) you want to pass to the script in it. The script can refer to these variables using the key specified in setVariable call.

Regards,


这篇关于从C#传递python脚本中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆