[IronPython] How to set __name__ for scriptengine instance?

Michael Foord fuzzyman at voidspace.org.uk
Sat Jul 18 00:06:51 CEST 2009


Jesse Wiles wrote:
> Hi,
> I looked in the archives a bit but nothing jumped out.  I'm trying to
> figure out how to set the __name__ for an embedded engine instance.
> Here's what I'm working with...
>   

__name__ should be set per scope. How about:

    scope.SetVariable("__name__", "__main__");

Michael
>       // I'm guessing here; not sure what these options should be and
> it was not obvious in tracing through the source
>       //
>       Dictionary<string, object> options = new Dictionary<string, object>();
>       options["ExceptionDetail"] = true;
>       options["ShowClrExceptions"] = true;
>
>       ScriptEngine engine = Python.CreateEngine(options);
>
>       // Again, grasping at straws...
>       //
>       IAttributesCollection symbols = new SymbolDictionary();
>       symbols[Symbols.Name] = "__main__";
>       ScriptScope scope = engine.CreateScope(symbols);
>
>       scope.SetVariable("MyFooHash", new Dictionary<string, string>());
>
>       engine.ExecuteFile(this.mPathTextBox.Text, scope);
>
> Thanks,
> Jesse Wiles
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>   


-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog





More information about the Ironpython-users mailing list