Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Run ironpython code, no output
#7
Also you can add py files to script assembly resources. In Properties dialog.

C# code:
// script "ipy_code3.cs" /*/ r Libraries\IronPython.dll; r Libraries\Microsoft.Scripting.dll; r Libraries\Microsoft.Dynamic.dll; resource script.py /string; /*/ //.
using Au; using System; using Microsoft.Scripting.Hosting;
using IronPython.Hosting;
using System.Collections.Generic;
using System.Linq;
partial class Script : AScript { [STAThread] static void Main(string[] a) => new Script(a); Script(string[] args) { //;;;
AOutput.RedirectConsoleOutput=true;

ScriptEngine engine = Python.CreateEngine();
ScriptSource source = engine.CreateScriptSourceFromString(Au.Util.AResources.GetString("script.py")); //or "subfolder/script.py"
ScriptScope scope = engine.CreateScope();

ObjectOperations op = engine.Operations;

source.Execute(scope); // class object created
object classObject = scope.GetVariable("MyClass"); // get the class object
object instance = op.Invoke(classObject); // create the instance
object method = op.GetMember(instance, "myMethod"); // get a method

List<string> result = ((IList<object>)op.Invoke(method)).Cast<string>().ToList();

AOutput.Write(result);

}
}


Messages In This Thread
Run ironpython code, no output - by macman - 01-07-2021, 11:27 AM
RE: Run ironpython code, no output - by Gintaras - 01-07-2021, 12:10 PM
RE: Run ironpython code, no output - by macman - 01-08-2021, 12:45 AM
RE: Run ironpython code, no output - by macman - 01-08-2021, 05:51 AM
RE: Run ironpython code, no output - by Gintaras - 01-08-2021, 06:12 AM
RE: Run ironpython code, no output - by Gintaras - 01-08-2021, 06:59 AM
RE: Run ironpython code, no output - by Gintaras - 01-08-2021, 07:29 AM
RE: Run ironpython code, no output - by macman - 01-08-2021, 08:42 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)