Exporting a Class from a .pyd

David Bolen db3l at fitlinxx.com
Thu Jul 5 22:31:15 EDT 2001


gerson.kurz at t-online.de (Gerson Kurz) writes:

> It is quite easy to export methods, and constants, and even datatypes
> from a .pyd (Python Extension DLL, .so in #?nix). However, how do you
> export a class ? Is it just a special way of exporting datatypes ?
> (But then, I cannot yet see how to add methods to such a datatype).
> I've looked up google but in vain.

New objects in extensions are formed by initializing an appropriate
structure with entry points (determined by Python and the basic type
of object you implement) for your object and then letting Python know
about it.  Methods are handled through the getattr slot (e.g., you
just look up the entry point for your method and return it as the
result).

That's one of the weaker sections of the existing documentation (what
information there is can be found mostly in the Python C/API
document), so you're best set to refer to either sample sources for
extensions or to the Python source itself.  There is an xxobject.c
file in the objects directory of the Python source that can be a good
starting point (as can be any of the other object implementation files
in that directory).

Note that these methods will actually give you a new type, but not
something that you can subclass from within your Python code.  If you
want that do some google searching on extension classes, which can
provide a way to do that, or - probably easier - try working with a
library such as Boost to make some of that work easier.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list