[IronPython] Convert between python array and .NET Array

David Escobar davidescobar at ieee.org
Sat Jun 12 08:27:39 CEST 2010


This worked for me (based on the code you provided):

import clr
from System import Array

dest = Array[str](bytes)



On Fri, Jun 11, 2010 at 9:51 PM, Marcel <marcel.vandendungen at gmail.com>wrote:

> I have a python method that returns a Python byte array.array('c').
>
> Now, I want to copy this array using
> System.Runtime.InteropServices.Marshal.Copy. This method however
> expects a .NET Array.
>
> import array
> from System.Runtime.InteropServices import Marshal
>
> bytes = array.array('c')
> bytes.append('a')
> bytes.append('b')
> bytes.append('c')
> Marshal.Copy(bytes, dest, 0, 3)
>
> Is there a way to make this work without copying the data? If not, how
> do I convert the data in the Python array to the .NET array?
>
> Thanks,
> -- Marcel
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20100611/82aef6bb/attachment.html>


More information about the Ironpython-users mailing list