how to make a custom python object?

E

elsejj

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top