Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initializing an Array[int] with Python .Net in Python

I'm using the Python .Net library so I don't have access to List<T>. Currently when I try to initialize an Array an error is thrown.

The documentation has an example that is throwing an error from the latest code base.

Ex:

from System import Array
myarray = Array[int](10) #TypeError: Cannot convert 10 to System.Int32[]

The following works on 64bit but not on 32bit!

myarray = Array[int]([10]) #OverflowError: value too large to convert
like image 215
pyCthon Avatar asked Oct 21 '25 03:10

pyCthon


1 Answers

I also get an error when I execute Array[int](10). It looks like the expected argument isn't the size, but a Python list. The following works for me:

py_array = [1, 2, 3]
net_array = Array[int](py_array)

Now, net_array.Length should return 3.

like image 194
antchi Avatar answered Oct 23 '25 15:10

antchi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!