how to make a custom python object?

Discussion in 'Python' started by elsejj, Oct 15, 2003.

  1. elsejj

    elsejj Guest

    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.
     
    elsejj, Oct 15, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?S2h1emVtYQ==?=

    Object Data Source and Custom Business Object

    =?Utf-8?B?S2h1emVtYQ==?=, Jun 27, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    786
    =?Utf-8?B?S2h1emVtYQ==?=
    Jun 27, 2005
  2. =?Utf-8?B?SmF5YnVmZmV0?=
    Replies:
    9
    Views:
    852
    Phillip Williams
    Feb 21, 2006
  3. Mark Asbach
    Replies:
    1
    Views:
    472
    Leo Kislov
    Nov 3, 2006
  4. David Bowey
    Replies:
    1
    Views:
    251
    David Bowey
    Mar 16, 2005
  5. Pokkai Dokkai
    Replies:
    8
    Views:
    139
    Phrogz
    Nov 18, 2007
Loading...

Share This Page