how to make a custom python object?
elsejj
elsejj at yahoo.com
Tue Oct 14 23:22:09 EDT 2003
i want make a new object named 'vector' to my python release,
the 'vector' is most like a 'list', but have some number operatioins
such as add, sub, ect. i create the head file vectorobject.h based
on listobject.h, i create the src file vectorobject.c based on
listobject.c and intobject.c.
1 i had create PyVectorObject like this
typedef struct {
PyObject_VAR_HEAD
double* ob_item;
} PyVectorObject;
2 i had create the PyVector_Type like this
PyAPI_DATA(PyTypeObject);
and initialize it in vectorobject.c like
PyTypeObject PyVector_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0,
"vector",
sizeof(PyVectorObject),
0,
(destructor)vector_dealloc, /* tp_dealloc */
(printfunc)vector_print, /* tp_print */
0, /* tp_getattr
*/
0, /* tp_setattr
*/
0, /* tp_compare */
0, /* tp_repr */
&vector_as_number, /*
tp_as_number */
0, /*
tp_as_sequence */
0, /*
tp_as_mapping */
...
but it dosen't works, i can't declare the object and used it, who
can tell me how to do, thanks very much.
More information about the Python-list
mailing list