embed python: how to call a class' function?
David Ang
davidang at info.com.ph
Wed May 28 12:16:05 EDT 2003
Hello,
thanks very much for your help. i will seek your code when i get back
to embedding python :)
Dave Kuhlman <dkuhlman at rexx.com> wrote in message news:<bb0lar$4cvv0$1 at ID-139865.news.dfncis.de>...
> David Ang wrote:
>
> > provide code pls.
>
> Here is some sample code -- It (1) checks to determine if the
> object (info->contentHandler) has an attribute "characters"; (2)
> creates a buffer of characters; (3) calls the method "characters"
> in the object passing one argument (the character buffer):
>
> if ((info->handlers.characters != NULL) &&
> (PyObject_HasAttrString(info->contentHandler, "characters")))
> {
> allocate = 0;
> if (len < 1024)
> {
> pBuf = buf;
> }
> else
> {
> pBuf = (char *)malloc(len + 1);
> allocate = 1;
> } /* if */
> strncpy(pBuf, ch, len);
> pBuf[len] = '\0';
> result = PyObject_CallMethod(info->contentHandler, "characters",
> "s", pBuf);
> if (allocate)
> {
> free(pBuf);
> } /* if */
> if (PyErr_Occurred())
> {
> PyErr_Print();
> } /* if */
> } /* if */
>
> >
> > also, where are the function references for embed python? i can't
> > find it on the docs, ie python library refence etc.,
>
> See:
>
> http://www.python.org/doc/current/ext/ext.html
> http://www.python.org/doc/current/api/api.html
>
> And, especially:
>
> http://www.python.org/doc/current/api/object.html
>
> If you really do mean to call a *class* method as opposed to an
> *instance* method, then I believe the above code will still serve
> as a model. But, the object will be the class itself, not an
> instance of the class.
>
> - Dave
More information about the Python-list
mailing list