Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using IronPython.Hosting;
- using Microsoft.Scripting;
- using Microsoft.Scripting.Hosting;
- namespace IronPythonTest
- {
- class Program
- {
- static void Main(string[] args)
- {
- ScriptEngine engine = Python.CreateEngine();
- string code = @"
- import System
- print System.Int32(5) #OK
- gen = (System.Int32(i) for i in range(1,10))
- for x in gen:
- print x
- ";
- ScriptSource source = engine.CreateScriptSourceFromString(code, SourceCodeKind.AutoDetect);
- CompiledCode compiledCode = source.Compile();
- try
- {
- compiledCode.Execute(engine.CreateScope()); // IronPython.Runtime.UnboundNameException
- }
- catch (System.Exception ex)
- {
- Console.WriteLine(ex.ToString());
- }
- try
- {
- compiledCode.Execute(); //OK
- }
- catch (System.Exception ex)
- {
- Console.WriteLine(ex.ToString());
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment