Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > how to make a custom python object?

Thread Tools

how to make a custom python object?

Posts: n/a
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 {
double* ob_item;
} PyVectorObject;

2 i had create the PyVector_Type like this
and initialize it in vectorobject.c like
PyTypeObject PyVector_Type = {
(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.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
install python to custom prefix with custom library directories =?utf-8?Q?Poor=20Yorick?= Python 0 07-17-2007 05:53 PM
How to test python extension modules during 'make check' / 'make distcheck'? Mark Asbach Python 1 11-03-2006 02:29 AM
How does one make use of sub files to make DVD? Bun Mui DVD Video 0 05-21-2006 03:24 PM
Anyone know how to make XP make a sound when typing? Like old dumb terminals? Fire Computer Support 6 02-17-2004 12:56 AM