NET программирование, и я не знаю, как передать аргумент из .NET функции класса в скрипте Python, поддерживаемом Ironpython
Вот мой скрипт .cs.
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using IronPython.Hosting;
namespace PrintToConsole
{
internal class Program
{
private static void Main()
{
Console.WriteLine("What would you like to print from python?");
var input = Console.ReadLine();
var py = Python.CreateEngine();
//var scope = py.CreateScope();
//scope.SetVariable("x", input);
try
{
//py.Execute("print('From Python: %s'%x)");
py.Execute("import x" );
py.Execute("s=x.operation()");
py.Execute("sum=s.add(input)");
py.Execute("print(sum)");
}
catch (Exception ex)
{
Console.WriteLine(
"Oops! We couldn't print your message because of an exception: " + ex.Message);
}
Console.WriteLine("Press enter to exit...");
Console.ReadLine();
}
}
}
А вот мой соответствующий скрипт на python.
import sys
class operation():
def __init__(self):
self.y=int(input('enter a no :'))
def add(self,x):
sum=sys.argv[1]+self.y
return(sum)
Кроме того, можно ли отправлять изображения, используя ту же технику?
Заранее спасибо!