Skip to content

Instantly share code, notes, and snippets.

@ironpythonbot
Created December 9, 2014 17:53
Show Gist options
  • Save ironpythonbot/a4084ed124242074bf11 to your computer and use it in GitHub Desktop.
Save ironpythonbot/a4084ed124242074bf11 to your computer and use it in GitHub Desktop.
CodePlex Issue #30308 Plain Text Attachments
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