4

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
2
  • 2
    how about myarray = Array[int]([10])? Commented Jan 7, 2015 at 14:29
  • @njzk2 fairly certain this is a bug I should bring up to the maintainers Commented Jan 7, 2015 at 15:16

3 Answers 3

10

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.

Sign up to request clarification or add additional context in comments.

4 Comments

This is the same example I have above, it works on 64-bit but not on 32-bit, this is most likely a bug in the package
I'm running PythonNet in 32-bit mode, and the example I gave above works fine.
How did you install Python .Net? The package maintainers were able to reproduce it here, github.com/pythonnet/pythonnet/issues/58
I got the source code from sourceforge.net/p/pythonnet/code/147/tree/trunk and compiled it for x86.
3

Use System.Array.CreateInstance(<type>, <length>)

refer to msdn

Comments

0

you can just write like this:

myarray = Array[int]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.