473,467 Members | 1,531 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Wrapping C++ Class Heirachy in Python

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
6 1845
> 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
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
>>>>> 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
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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Roy Smith | last post by:
I've got a C library with about 50 calls in it that I want to wrap in Python. I know I could use some tool like SWIG, but that will give me a too-literal translation; I want to make some...
4
by: Lawrence Oluyede | last post by:
I've never used metaclasses in real life before and while searching through the online Cookbook I found this gorgeous example: "Wrapping method calls (meta-class example)"...
3
by: gabriel.becedillas | last post by:
Hi, I'm having problems wrapping a hierarchy of classes, actually having problems wrapping the base class. I don't need to use the WrapClass mechanism since I don't want to override classes in...
3
by: Paul Anton Letnes | last post by:
Hello guys, (related to previous thread on wrapping C/C++ in Python, trying the SWIG approach.) Trying to map a C++ class to python, one method for now. Running the following commands to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.