﻿

using System;
using System.IO;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;

namespace IronPythonNameTest
{
	public static class ScriptExecutor
	{

		private static void Main()
		{
			try
			{
				using (StreamWriter writer = new StreamWriter("test.py"))
				{
					writer.WriteLine("print 'name:', __name__");
				}

				ScriptEngine engine = Python.CreateEngine();

				ScriptScope mainScope = engine.CreateScope();
				mainScope.SetVariable("__name__", "__main__");

				ScriptSource scriptSource = engine.CreateScriptSourceFromFile("test.py");

				scriptSource.Compile();
				ScriptSource source = scriptSource;

				source.Execute(mainScope);
			}
			finally
			{
				Console.WriteLine("Script Finished");
				Console.ReadLine();
			}
		}
	}
}


