Reading the documentation here, I see that you can use ctypes.Structure as follows :-
>>> class Int(Structure):
... _fields_ = [("first_16", c_int, 16),
... ("second_16", c_int, 16)]
...
>>> print Int
Would it be possible for me to create such a class by using a list that I decide upon dynamically? For eg, something along the lines of :-
def int_factory(fields):
int_class = get_int_class(fields) # This returns a class object with _fields_ set to fields
return int_class
def user(values=[1,2]):
int_class = int_factory(int_fields)
i = int_class(values[0], values[1])
Would it be possible to do this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…