static void Main(string[] args) { // Create simple host environment var host = new DlrHost <IronPythonLanguage>(new IronPythonLanguage()); host.AddSearchPath(@"C:\Program Files (x86)\IronPython 2.7\Lib\"); // Add some resolver for embedded scripts/modules //host.AddImportResolver(new EmbeddedModuleResolver()); // Execute script by path //var val = host.DefaultScope.ExecuteScript("FileSample/FileSample.py"); //Console.WriteLine("Script value: " + val.ToString()); // Import some classes and use them host.DefaultScope.Execute("" // + "from System import Console" + "\r\n" //+ "import os\r\n" // + "import Math.MathImpl" + "\r\n" + "from importlib import import_module" + "\r\n" + "import_module('collections')" + "\r\n" //+ "globals()['defaultdict'] = getattr(import_module('collections'), 'defaultdict')" + "\r\n" //+ "print defaultdict" + "\r\n" //+ "# Ausgabe: <type '_collections.defaultdict'>" + "\r\n" //+ "import Simplic.Dlr" + "\r\n" + "" + "\r\n" //+ "Console.WriteLine(str(Math.add(1, 2)))" + "\r\n" + "" + "\r\n" + "" + "\r\n" + "" + "\r\n"); Console.ReadLine(); }
static void Main(string[] args) { if (args.Length > 0) { // Create host var language = new IronPythonLanguage(); language.Argv = args.ToList(); var host = new DlrHost <IronPythonLanguage>(language); host.AddSearchPath(@"C:\Program Files (x86)\IronPython 2.7\Lib\"); host.AddSearchPath(System.IO.Path.GetDirectoryName(args[0])); try { host.DefaultScope.ExecuteScript(args.First()); } catch (Exception ex) { Environment.Exit(1); } } }
static void Main(string[] args) { if (args.Length > 0) { // Create host var language = new IronPythonLanguage(); language.Argv = args.ToList(); var host = new DlrHost<IronPythonLanguage>(language); host.AddSearchPath(@"C:\Program Files (x86)\IronPython 2.7\Lib\"); host.AddSearchPath(System.IO.Path.GetDirectoryName(args[0])); try { host.DefaultScope.ExecuteScript(args.First()); } catch (Exception ex) { Environment.Exit(1); } } }
static void Main(string[] args) { // Create simple host environment var host = new DlrHost<IronPythonLanguage>(new IronPythonLanguage()); host.AddSearchPath(@"C:\Program Files (x86)\IronPython 2.7\Lib\"); // Add some resolver for embedded scripts/modules //host.AddImportResolver(new EmbeddedModuleResolver()); // Execute script by path //var val = host.DefaultScope.ExecuteScript("FileSample/FileSample.py"); //Console.WriteLine("Script value: " + val.ToString()); // Import some classes and use them host.DefaultScope.Execute("" // + "from System import Console" + "\r\n" //+ "import os\r\n" // + "import Math.MathImpl" + "\r\n" + "from importlib import import_module" + "\r\n" + "import_module('collections')" + "\r\n" //+ "globals()['defaultdict'] = getattr(import_module('collections'), 'defaultdict')" + "\r\n" //+ "print defaultdict" + "\r\n" //+ "# Ausgabe: <type '_collections.defaultdict'>" + "\r\n" //+ "import Simplic.Dlr" + "\r\n" + "" + "\r\n" //+ "Console.WriteLine(str(Math.add(1, 2)))" + "\r\n" + "" + "\r\n" + "" + "\r\n" + "" + "\r\n"); Console.ReadLine(); }