using System; using System.Windows; using IronPython.Hosting; namespace WpfApplication3 { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void ButtonBase_OnClick(object sender, RoutedEventArgs e) { try { var strExpression = @" import sys sys.stdout=my for i in range(1, 5): print i "; var engine = Python.CreateEngine(); var scope = engine.CreateScope(); var sourceCode = engine.CreateScriptSourceFromString(strExpression); scope.SetVariable("my", this); var actual = sourceCode.Execute(scope); TextBlock.Text += actual; } catch (Exception ex) { //TextBlock.Text += ex.ToString(); MessageBox.Show(ex.ToString()); } } public bool softspace; public void write(string s) { TextBlock.Text += s; } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)