7

How do you create an array of defined length of the certain type in python? To be precise I am trying to create an array of handles that is able to hold up to 1024 records. I figured out an analog to HANDLE type in python, which would be c_void_p of ctypes.

For example C++ code would have:

HANDLE myHandles[1024];

What would be python analogy to the C++ code above? Thank you for your input.

1

2 Answers 2

7

You've already accepted an answer, but since you tagged ctypes you might want to know how to create arrays of ctypes types:

>>> import ctypes
>>> ctypes.c_void_p * 1024                # NOTE: this is a TYPE
<class '__main__.c_void_p_Array_1024'>
>>> (ctypes.c_void_p * 1024)()            # This is an INSTANCE 
<__main__.c_void_p_Array_1024 object at 0x009BB5D0>
Sign up to request clarification or add additional context in comments.

Comments

4

In python, you generally just create an array, and you can put any values you like in it. It's dynamic.

my_handles = []

You can put as many of any type of values in this as you want now. ...is there a specific reason you want to create a specific type and a specific length?

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.