06-07-2023, 06:07 PM
This is basically cribbed from the IronPython 3 page here, but adding some code to get LA variables (one from a dialog) into the Python code, and Python results back out to LA. Also changed the string concatenation to 'string.format()' syntax. I used 'Tools -> NuGet' to add the 'ironpython' package. I just entered for 'ironpython' in the dialog and it pulled 3.4, which is what I wanted (good thing, I don't even see IronPython 2 available on the NuGet Gallery page).
Regards,
burque505
/*/ nuget -\ironpython; /*/
string name = "";
var date = DateTime.Now.ToString("MMMM dd, yyyy");
if(!dialog.showInput(out name, "Enter your name for a greeting.", title: "Iron Python input test")) return;
print.it(name);
var eng = IronPython.Hosting.Python.CreateEngine();
var scope = eng.CreateScope();
eng.Execute(@"
def greetings(name, date):
return 'Hello {}, today is {}'.format(name,date)
", scope);
dynamic greetings = scope.GetVariable("greetings");
// System.Console.WriteLine(greetings(name, date));
dialog.show("Output via IronPython", greetings(name,date), title: "IronPython at work", secondsTimeout: 10);
Regards,
burque505