Created
December 9, 2014 17:53
-
-
Save ironpythonbot/a4084ed124242074bf11 to your computer and use it in GitHub Desktop.
CodePlex Issue #30308 Plain Text Attachments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} | |
catch (System.Exception ex) | |
{ | |
Console.WriteLine(ex.ToString()); // IronPython.Runtime.UnboundNameException | |
} | |
try | |
{ | |
compiledCode.Execute(); // Ok | |
} | |
catch (System.Exception ex) | |
{ | |
Console.WriteLine(ex.ToString()); | |
} | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment