Re: [Python.NET] Installing Python for .NET with .NET 2.0?
Hi Alberto - Thanks for your help! Seems to work fine now....except...I am trying to use arrays. I am following the README on the python for .NET website. Here are the commands I am trying to run: from System import Array # works! myarray = Array[int](10) # fails! TypeError: Cannot convert 10 to System.Int32[] I'm a little confused...obviously the example doesn't work, but how *should* arrays be initialized in Python .NET? The c# code might look like: int[,] numbers = new int[,] { {1, 2}, {3, 4}, {5, 6} }; I'm actually looking to make a 2D array. Further, the end goal is to make a 2D array...then serialize it....then deserialize it in c# code itself. I'm hoping to make this a transport layer between Python and C#. It's a bit complicated, but I have an existing application in Python which I want to get some calculated results out of without writing listeners, named pipes, web services, etc. All I want to do is to serialize a .NET 2D array created in Python. - Aaron
-----Original Message----- From: pythondotnet-bounces@python.org [mailto:pythondotnet-bounces@python.org] On Behalf Of Alberto Berti Sent: Friday, April 20, 2007 1:49 AM To: pythondotnet@python.org Subject: Re: [Python.NET] Installing Python for .NET with .NET 2.0?
Hi Aaron,
the tarballs on pythondotnet's site are for .NET 1, if you want to use it with .NET 2 you should checkout the last svn trunk and patch it with the instruxtions described in this mail http://thread.gmane.org/gmane.comp.python.dotnet/576 .In that message there is also a link to binary packages provided by Angel Ignacio.
Hi hope soon to set up a wiki dedicated to pythondotnet as there aren't so many examples of using it for things like embedding etc. I'm just looking for a wiki engine which as some effective spam protection. If someone has any hint on a product or a service please drop me a line.
Alberto _________________________________________________ Python.NET mailing list - PythonDotNet@python.org http://mail.python.org/mailman/listinfo/pythondotnet
Hi Aaron - PythonNet tip 'o the day: you can probably just construct the array in Python as a normal list: mylist = [[1, 2], [3, 4], ...] If you pass that to a method with a signature that takes int[,] then everything should Just Work so long as the lists and their contents are actually convertible to the stated type ;) The syntax you're using below is actually trying instantiate a bound generic type (Array[int] is equivalent to Array<int> in C#), so when you say 'Array[int](10)' it is trying to create the bound generic type and initialize it with 10 (which is not an array), which is probably not what you intended. hope this helps, -Brian On 4/20/07 4:59 PM, "Aaron Rubin" <Aaron.Rubin@4DTechnology.com> wrote:
Hi Alberto -
Thanks for your help! Seems to work fine now....except...I am trying to use arrays. I am following the README on the python for .NET website. Here are the commands I am trying to run:
from System import Array # works! myarray = Array[int](10) # fails! TypeError: Cannot convert 10 to System.Int32[]
I'm a little confused...obviously the example doesn't work, but how *should* arrays be initialized in Python .NET? The c# code might look like: int[,] numbers = new int[,] { {1, 2}, {3, 4}, {5, 6} };
I'm actually looking to make a 2D array. Further, the end goal is to make a 2D array...then serialize it....then deserialize it in c# code itself. I'm hoping to make this a transport layer between Python and C#. It's a bit complicated, but I have an existing application in Python which I want to get some calculated results out of without writing listeners, named pipes, web services, etc. All I want to do is to serialize a .NET 2D array created in Python.
- Aaron
-----Original Message----- From: pythondotnet-bounces@python.org [mailto:pythondotnet-bounces@python.org] On Behalf Of Alberto Berti Sent: Friday, April 20, 2007 1:49 AM To: pythondotnet@python.org Subject: Re: [Python.NET] Installing Python for .NET with .NET 2.0?
Hi Aaron,
the tarballs on pythondotnet's site are for .NET 1, if you want to use it with .NET 2 you should checkout the last svn trunk and patch it with the instruxtions described in this mail http://thread.gmane.org/gmane.comp.python.dotnet/576 .In that message there is also a link to binary packages provided by Angel Ignacio.
Hi hope soon to set up a wiki dedicated to pythondotnet as there aren't so many examples of using it for things like embedding etc. I'm just looking for a wiki engine which as some effective spam protection. If someone has any hint on a product or a service please drop me a line.
Alberto _________________________________________________ Python.NET mailing list - PythonDotNet@python.org http://mail.python.org/mailman/listinfo/pythondotnet
_________________________________________________ Python.NET mailing list - PythonDotNet@python.org http://mail.python.org/mailman/listinfo/pythondotnet
"Brian" == Brian Lloyd <brian.lloyd@revolution.com> writes:
Brian> Hi Aaron - PythonNet tip 'o the day: you can probably just Brian> construct the array in Python as a normal list: Brian> mylist = [[1, 2], [3, 4], ...] Brian> If you pass that to a method with a signature that takes Brian> int[,] then everything should Just Work so long as the Brian> lists and their contents are actually convertible to the Brian> stated type ;) that is good! :-) Brian> The syntax you're using below is actually trying Brian> instantiate a bound generic type (Array[int] is equivalent Brian> to Array<int> in C#), so when you say 'Array[int](10)' it Brian> is trying to create the bound generic type and initialize Brian> it with 10 (which is not an array), which is probably not Brian> what you intended. i should better understand what generic types are.... thanks Alberto P.S. Any commente on my idea of a wiki for pythondotnet?
"Aaron" == Aaron Rubin <Aaron.Rubin@4DTechnology.com> writes:
Hi Aaron, Aaron> from System import Array # works! Aaron> myarray = Array[int](10) # fails! TypeError: Cannot.... the correct semantic is myarray = Array[int]((0,1,2,3,4,5,6,7,8,9)) Aaron> I'm a little confused...obviously the example doesn't work, Aaron> but how *should* arrays be initialized in Python .NET? The Aaron> c# code might look like: int[,] numbers = new int[,] { {1, Aaron> 2}, {3, 4}, {5, 6} }; i wasn't able to find the correct way to create an instance of a multidimensional Array... i think that actually it is not possible, but maybe someone can correct me here. Aaron> I'm actually looking to make a 2D array. Further, the end Aaron> goal is to make a 2D array...then serialize it....then Aaron> deserialize it in c# code itself. I'm hoping to make this Aaron> a transport layer between Python and C#. It's a bit Aaron> complicated, but I have an existing application in Python Aaron> which I want to get some calculated results out of without Aaron> writing listeners, named pipes, web services, etc. All I Aaron> want to do is to serialize a .NET 2D array created in Aaron> Python. I'm at the very start of my Python embedding journey, but since now i prefer to work with native Python objects on that side, and then deal with messy stuff at the messy level (read c#). So list and tuples become PyList, PyTuples and you can iterate or convert them appropriately. I do not know however if that is the correct way to do such things..... hope it helps Alberto
participants (3)
-
Aaron Rubin
-
Alberto Berti
-
Brian Lloyd