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

Wrapping C++ Class Heirachy in Python

P: n/a
Hi,

I'm trying to wrap a C++ class hierarchy with Python types and I'd like to
maintain the hierarchy in the types. I'm fairly sure this is possible,
isn't it?

Are there any documents explaining how to do this, the standard Python
manual doesn't go into enough detail about creating types for this.

I've found the tp_base and tp_bases elements and I've set them to the base
type object (and a tuple containing the base type object) before I call
PyType_Ready but in Python the base class isn't recognised. Is there
anything obvious I'm missing?

Thanks in advance for any help,
Andrew Wilkinson

Jul 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
> PyType_Ready but in Python the base class isn't recognised. Is there
anything obvious I'm missing?


Maybe - I'd go for one of the several available python wrapper generators. I
personally had good experiences with SIP. But you might also try boost
python or SWIG.

The python C-API is great - for C. For C++, use one of the above.
--
Regards,

Diez B. Roggisch
Jul 19 '05 #2

P: n/a
On 4/18/05, Andrew Wilkinson <aj******@spamyork.ac.uk> wrote:
I'm trying to wrap a C++ class hierarchy with Python types and I'd like to
maintain the hierarchy in the types. I'm fairly sure this is possible,
isn't it?
Yes.
Are there any documents explaining how to do this, the standard Python
manual doesn't go into enough detail about creating types for this.
Amen.
I've found the tp_base and tp_bases elements and I've set them to the base
type object (and a tuple containing the base type object) before I call
PyType_Ready but in Python the base class isn't recognised. Is there
anything obvious I'm missing?


Well, I can't really recommend without seeing what you did (did you
remember the preceding "&" for the type struct?

Otherwise, I'd have to recommend Objects/unicodeobject.c in the Python
source as a reference for how to do this.

I've had a couple of questions about how to implement new types that I
posted to the list, and never got much help, so I started using the
Python source as a reference. I've gotten most of what I needed to
know from there.

HTH
--
Steve Juranich
Tucson, AZ
USA
Jul 19 '05 #3

P: n/a
>>>>> Diez B Roggisch <de*********@web.de> writes:
PyType_Ready but in Python the base class isn't recognised. Is
there anything obvious I'm missing?
Maybe - I'd go for one of the several available python wrapper
generators. I personally had good experiences with SIP. But you
might also try boost python or SWIG. The python C-API is great - for C. For C++, use one of the
above. -- Regards, Diez B. Roggisch

http://boost.org/libs/python/doc/index.html might meet the
requirements.
R,
C
Jul 19 '05 #4

P: n/a
In article <um***********@bigfoot.com>,
Chris Smith <sm*************@bigfoot.com> wrote:
>> Diez B Roggisch <de*********@web.de> writes: >> PyType_Ready but in Python the base class isn't recognised. Is
>> there anything obvious I'm missing?

> Maybe - I'd go for one of the several available python wrapper
> generators. I personally had good experiences with SIP. But you
> might also try boost python or SWIG.

> The python C-API is great - for C. For C++, use one of the
> above. -- Regards,


I've been playing around with ctypes
(http://starship.python.net/crew/theller/ctypes/) recently. So far, it
looks pretty cool.
Jul 19 '05 #5

P: n/a

Roy> I've been playing around with ctypes
Roy> (http://starship.python.net/crew/theller/ctypes/) recently. So
Roy> far, it looks pretty cool.

Wrapping C++ libraries?

Skip

Jul 19 '05 #6

P: n/a
Steve Juranich wrote:
I've found the tp_base and tp_bases elements and I've set them to the
base type object (and a tuple containing the base type object) before I
call PyType_Ready but in Python the base class isn't recognised. Is there
anything obvious I'm missing?
Well, I can't really recommend without seeing what you did (did you
remember the preceding "&" for the type struct?


I realised it will be a little difficult to help without seeing my source,
but I was hoping someone would point me to some documentation so I wouldn't
have to cut my source down to an example suitable for a usenet post.
* Otherwise, I'd have to recommend Objects/unicodeobject.c in the Python
source as a reference for how to do this.


Thanks! I was trying to think of a built in object hierarchy in Python, I
didn't think of unicode strings.

Cheers!

Andrew

Simple distributed computing with Python...
PyLinda - http://www-users.cs.york.ac.uk/~aw/pylinda
Jul 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.