[IronPython] Modules in hosted enviroment

Ross Hammermeister glitch17 at gmail.com
Tue Jun 22 16:41:30 CEST 2010

My program creates data for a python script to use and I though the best way 
for it get access to this was with modules. Simply setting a variable in the 
script would not work because of the complexity of the data. Using the clr 
module will not get access to the existing data (I also do not want to grant 
access to all the other libraries). So I am left with creating a module but 
using a static class and assigning all the instances to the static classes 
every time before I call the python script is not a great method but I'm 
thinking this would be the best at this point. The other method I found was 
using the IronPython.Runtime.PythonModule class and Creating an instance for 
each of my modules and adding to using 
PythonEngine.Runtime.Globals.SetVariable The procedure to do this doesn't 
give the impression that what I'm doing was ever intended and I have hit 
things that I cannot do using this method. So I'm looking for a good method 
of creating modules that would have my data attached to them.


From: "Jeff Hardy" <jdhardy at gmail.com>
Sent: Monday, June 21, 2010 11:24 AM
To: "Discussion of IronPython" <users at lists.ironpython.com>
Subject: Re: [IronPython] Modules in hosted enviroment

> On Sat, Jun 19, 2010 at 10:51 PM, Ross Hammermeister <glitch17 at gmail.com> 
> wrote:
>> I have a project where I am hosting IronPython and I was wondering what 
>> is
>> the best way to create modules in C# for python to use. I have found two
>> ways to do it so far. One method is what is done in IronPython, where 
>> static
>> classes and the PythonModule attribute are used but I don't want to use
>> static classes to access runtime data.
> I'm not 100% sure what you mean here, but the static class is just a
> container - and it can contain non-static classes (and functions, and
> static variables, etc). If it needs to be a module, it's the way to
> go, as far as I'm concerned. If things get too big, don't forget that
> you can use partial classes to split things up.
> However, depending on what your code does, you probably don't need to
> make it a module - IronPython will work just fine with any .NET class
> library. Just do a `clr.AddReference` and then import the classes.
> - Jeff
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

More information about the Ironpython-users mailing list