How to import static class (or static method) into IronPython (or DLR) using C# code(not python)?
Asked Answered
P

1

5

scope.SetVariable("math", ?? typeof(System.Math) ??);

or do I need create a module?

Plumbism answered 19/8, 2009 at 14:15 Comment(0)
S
7

You can do:

scope.SetVariable("math", DynamicHelpers.GetPythonTypeFromType(typeof(System.Math)));

DynamicHelpers is in IronPython.Runtime.Types.

Staten answered 19/8, 2009 at 17:20 Comment(3)
And did you know how to create a ScripeScope that has parent scope?Plumbism
There's no way to do this - while Scope's have a Parent property ScriptScope's don't expose this. The parent property on Scope's is also going away. If you want to chain lookups you should create a ScriptScope w/ your own custom IAttributesCollection which knows how to look in the parent scope.Staten
Thank you.I found I could create a Scope with a parent scope using Scope(Scope parent, IAttributesCollection dictionary), and HostingHelpers can create a ScriptScope from a Scope.Plumbism

© 2022 - 2024 — McMap. All rights reserved.