Discussion:
[Python.NET] IronPython Embeddied .NET 4.0, how to transfer object from C# into Ironpython and back again
riscy00
2012-05-17 13:01:36 UTC
Permalink
I'm learning more about data/object transfer between C# and ironpython (under
embedded within NET4)

I have class object instance containing Dictionary<T> implementation with
data such as "XDATA:67, YDATA:12,ZDATA:66"

I also have test.py filename which is loaded into C#'s IRONPYTHON (using var
and dynamic method). I was curious how to transfer data within the class
object into Python (reference class or a copy?) which do various processing
(ie ZDATA=YDATA+XDATA) and then return result within the same class (rather
than value)

Is this possible, if so please demonstrate code example in C# and python.

How to make sure both Dictionary within C# is the same as python?

The whole aim is to pass object instance into python and do operation task
using object data and then pass data back into class and make it available
to return object back to the C# for further processing.

I wondered if this can this be done by mean of reference (rather than copy?,
faster and more compact this way perhaps).





--
View this message in context: http://python.6.n6.nabble.com/IronPython-Embeddied-NET-4-0-how-to-transfer-object-from-C-into-Ironpython-and-back-again-tp4974924.html
Sent from the Python - pythondotnet mailing list archive at Nabble.com.
_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet
riscy00
2012-05-17 18:33:25 UTC
Permalink
In addition, as an example for LIST<T> basis (rather than Dictionary for
which I primary interested once I get hang of the below....

In Python
=======================================================
class Pointer(object): #class definition
def __init__(self, alist, index):
self.alist = alist
self.index = index

def get(self): # get
return self.alist[self.index]

def set(self, value): # set
self.alist[self.index] = value

def find(q):
return Pointer(q, 0)

def Process():
list1 = [1, 2, 3] #list object
p = find(list1) #this create instance of the
Pointer object with p as reference and then implement list value
p.set(0) #Modify the list value on index
0
return list1
=====================================================================
I also have C# .NET4 with embedded python
In C#
=====================================================================
private void btnRun2_Click(object sender, EventArgs e)
{
// C# Side
var runtime = Python.CreateRuntime();
dynamic test = runtime.UseFile(m_sFilename); // filename point
to test.py (above code)
var result = test.Process();
rtbConsole.Text += result.ToString();
}
=======================================================================
Under debug, I can see result containing the list element 1,2,3 (with
data)...which is great.

(a) How to pass the LIST<T> in C# to python
(b) How to pass the LIST<T> back to C# after python calculation routine.
(c) How to make return result into LIST<T> from the above....

Your input would be appreciated.






--
View this message in context: http://python.6.n6.nabble.com/IronPython-Embeddied-NET-4-0-how-to-transfer-object-from-C-into-Ironpython-and-back-again-tp4974924p4974958.html
Sent from the Python - pythondotnet mailing list archive at Nabble.com.
_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet

Loading...