Creating Python Class Instances From C API

Adrian Eyre a.eyre at optichrome.com
Wed Oct 13 04:17:48 EDT 1999


> PyObject *data = Py_BuildValue("{s:s}", "<name>", "<value>");
> PyObject *object = PyInstance_New(class_name, NULL, data);

If you check out the code in Modules/newmodule.c, you can even
create an instance of a class without calling its constructor.

This can be very handy for having an instance returned from
a different class, which can't be instantiated by the Python
programmer.

--------------------------------------------
Adrian Eyre <mailto:a.eyre at optichrome.com>
Optichrome Computer Solutions Ltd
Maybury Road, Woking, Surrey, GU21 5HX, UK
Tel: +44 1483 740 233  Fax: +44 1483 760 644
http://www.optichrome.com 
--------------------------------------------





More information about the Python-list mailing list