[IronPython] Modules in hosted enviroment
jdhardy at gmail.com
Tue Jun 22 17:26:48 CEST 2010
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
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.
> 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>
>>> I have a project where I am hosting IronPython and I was wondering what
>>> 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
>>> 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
> Users mailing list
> Users at lists.ironpython.com
More information about the Ironpython-users