开发者

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.


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>


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜