5

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

or do I need create a module?

1 Answer 1

7

You can do:

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

DynamicHelpers is in IronPython.Runtime.Types.

Sign up to request clarification or add additional context in comments.

3 Comments

And did you know how to create a ScripeScope that has parent scope?
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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.