I'm trying to use ctypes to extract data from internal python structures. Namely, I'm trying to read the 4 fields in an xrange:
typedef struct {
PyObject_HEAD
long start;
long step;
long len;
} rangeobject;
Is there any standard way of getting at such fields within python itself?
You can access data you need without
ctypes
:Note, that
__reduce__()
method is exactly for serialization. Read this chapter in documentation for more information.Update: But sure you can access internal data with
ctypes
too: