user39602 user39602 - 6 months ago 61
Python Question

AttributeError: _fields_ is final (in python)

While writing a python script using ctypes, I'm getting an error :AttributeError: fields is final

typedef struct data
char * status;

//python script
import ctypes
import sys
from ctypes import *

class data(Structure):pass
data._fields_ = [('Status',POINTER(c_char))]

So, I have hereby shown the structure in .h file and also the way I'm defining the same structure in python using ctypes.
Can anyone suggest me the solution to the problem?


You can't change the _fields_ attribute of a Structure after the class has been created. The correct declaration would be:

class data(Structure):
    _fields_ = [('Status',POINTER(c_char))]