By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,678 Members | 1,158 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,678 IT Pros & Developers. It's quick & easy.

Creating a new object of your own type in a C extension.

P: n/a
Hi all!

Just a small question concerning type creation in a C object: If I create a
class which is overridable, I'd like to have that class create objects of
it's overridden type, e.g. I have a class X which is implemented in C, which
is wrapped in Python by a class Y, now I initialize a Y class, and call a
member of X on that class, and I'd like the member of X to return an object
of class Y. What is a correct way of doing this? I've not found any nice
implementation hints in the documentation...

1) PyObject_New(Xstruct, self->ob_type (which should point to the type of Y))
2) self->ob_type->tp_new(self->ob_type,NULL,NULL)
3) anything else?

I don't see any of this being used in the Python object classes (e.g.
overridden classes of int return int when e.g. __add__ is called, etc.).

Thanks for any help!


Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.