'How to create array of the certain type in python
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.
Solution 1:[1]
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>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mark Tolonen |
