Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 652
PSS Avatar asked Jul 26 '26 18:07

PSS


1 Answers

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>
like image 59
Mark Tolonen Avatar answered Jul 28 '26 08:07

Mark Tolonen