[IronPython] Modules in hosted enviroment

Dino Viehland dinov at microsoft.com
Tue Jun 22 18:58:48 CEST 2010


Alternately you could implement IAttributesCollection and execute the
Python code against a scope which is backed by the IAC.  This would
let you lazily provide the values to the script on-demand.  If you have
a fixed set of members I like Jeff's suggestion more but this is good if
the members are being generated dynamically.

> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-
> bounces at lists.ironpython.com] On Behalf Of Jeff Hardy
> Sent: Tuesday, June 22, 2010 8:27 AM
> To: Discussion of IronPython
> Subject: Re: [IronPython] Modules in hosted enviroment
> 
> Hi Ross,
> Sorry if I'm being dense, but here's how I understand what you're doing:
> 
> - you're hosting IronPython in some program X
> - X will generate data D and somehow feed D to Python script Y
> - Y will transform or process D in some way
> 
> What you're looking for is the best way to get D into Y, correct?
> 
> I think creating a module is the wrong way to go about this; modules
> are supposed to contain code and constant data, as the IronPython
> engine will only load them once and share them.
> 
> Why is setting a variable for the Python script to use not suitable?
> If it needs to be a complex object, you can create a (non-static)
> class in C#, fill it out, and pass an instance to the Python script
> using ScriptScope.SetVariable.
> 
> - Jeff
> 
> On Tue, Jun 22, 2010 at 8:41 AM, Ross Hammermeister <glitch17 at gmail.com>
> wrote:
> > 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.
> >
> > Thanks
> > Ross
> >
> > --------------------------------------------------
> > 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
> >>
> > _______________________________________________
> > Users mailing list
> > Users at lists.ironpython.com
> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> >
> _______________________________________________
> 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