[IronPython] How to place static class in script name space

Dino Viehland dinov at microsoft.com
Mon Jun 13 19:21:46 CEST 2011

We specifically allow from staticclass import * because we treat a static class as if it were like a module.  So you could simply run that line of code in the scope on behalf of the user.  Otherwise you'll need to re-create getting the dynamic members and then setting them in the scope.  Then you can use PythonOps.GetAttrNames to get the defined names and finally PythonOps.GetBoundAttr to get the actual members which you'll then set in the scope.

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Tom Unger
Sent: Monday, June 13, 2011 10:16 AM
To: 'users at lists.ironpython.com'
Subject: [IronPython] How to place static class in script name space

I am using IronPython for scripting an application.  To make writing scripts easier I want to place several objects in the script name space so they can be easily used.  I got stuck with how to place a reference to a static object, "App", in the name space.  This is probably a simple operation and just don't know what it is.

1. Python import works:

            from AppFrame import App

gives the script access to the static fields and methods on App.

But I want to eliminate the need for each script to do that import by setting up the scope with:

   scriptScope.SetVariable("App", App);
This does not compile because App is a static class, not an object.

How does my hosing application place a reference to the static class in the script's scope such that it can be used as if it was imported?



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20110613/9047ffc7/attachment.html>

More information about the Ironpython-users mailing list