473,769 Members | 8,283 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python C++

Hi!

Is it possible to easyly integrate c++ classes in python?

I don't want to use boost c++.

Does anyone know how to start or where to find documentation for this?

thx
Jul 18 '05 #1
9 2769
On Friday 16 July 2004 10:08 pm, Francois Fernandes wrote:
Hi!

Is it possible to easyly integrate c++ classes in python?

I don't want to use boost c++.

Does anyone know how to start or where to find documentation for this?


http://www.river-bank.demon.co.uk/docs/sip/sipref.html

Phil
Jul 18 '05 #2
Francois Fernandes wrote:
Does anyone know how to start or where to find documentation for this?


I would use the standard C API:

http://docs.python.org/ext/ext.html
http://docs.python.org/api/api.html

Regards,
Martin

Jul 18 '05 #3
Francois Fernandes wrote:
Hi!

Is it possible to easyly integrate c++ classes in python?

I don't want to use boost c++.

Does anyone know how to start or where to find documentation for this?

thx


Your choices are:
- SWIG http://www.swig.org/
- SIP (Phil Thompson has already provided the URL)
- Boost.Python (you already know about this it appears)

--
Mike
Jul 18 '05 #4
Phil Thompson <ph**@riverbank computing.co.uk > writes:
On Friday 16 July 2004 10:08 pm, Francois Fernandes wrote:
Hi!

Is it possible to easyly integrate c++ classes in python?

I don't want to use boost c++.

Does anyone know how to start or where to find documentation for this?


http://www.river-bank.demon.co.uk/docs/sip/sipref.html


Excellent -- looks like comprehensive documentation with enough of a
tutorial element to smooth the path a bit. Boost Python has some
competition.

(sip has been around for a long time, but until recently there were no
docs to speak of.)

SWIG used to be pretty poor for wrapping C++. Has it got better?
John
Jul 18 '05 #5
> > > Is it possible to easyly integrate c++ classes in python?


http://www.river-bank.demon.co.uk/docs/sip/sipref.html

SWIG used to be pretty poor for wrapping C++. Has it got better?


A couple of months ago when I looked at SWIG, it seemed to support almost
every C++ feature (templates and all), but I ended up not needing it so I
can't say how that translates in practice.

One problem with Boost is that it is such a big library and you have to get
the whole thing even if you just need a couple of "packages".

Oliver
Jul 18 '05 #6
Francois Fernandes wrote:
Hi!

Is it possible to easyly integrate c++ classes in python?

I don't want to use boost c++.

Does anyone know how to start or where to find documentation for this?


I prefer PyCXX http://cxx.sourceforge.net
--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
Jul 18 '05 #7
Helmut Jarausch wrote:
Francois Fernandes wrote:
Hi!

Is it possible to easyly integrate c++ classes in python?

I don't want to use boost c++.

Does anyone know how to start or where to find documentation for this?


I prefer PyCXX http://cxx.sourceforge.net


Looks interesting. I want to expose lots of signal processing algorithms
written in C++ to python. I want to use std::vector for containers,
because they are fast. I need to create python types for
std::vector<dou ble> and std::vector<std ::complex<doubl e>> at minimum. The
Python interface doesn't need to know much about these types, just be able
to create vectors of a given size.

Would PyCXX be a good choice for this? Are there any samples of code
similar to this?

Jul 18 '05 #8
Neal D. Becker wrote:
Helmut Jarausch wrote:

Francois Fernandes wrote:
Hi!

Is it possible to easyly integrate c++ classes in python?

I don't want to use boost c++.

Does anyone know how to start or where to find documentation for this?


I prefer PyCXX http://cxx.sourceforge.net

Looks interesting. I want to expose lots of signal processing algorithms
written in C++ to python. I want to use std::vector for containers,
because they are fast. I need to create python types for
std::vector<dou ble> and std::vector<std ::complex<doubl e>> at minimum. The
Python interface doesn't need to know much about these types, just be able
to create vectors of a given size.

Would PyCXX be a good choice for this? Are there any samples of code
similar to this?


I think, yes. PyCXX allows for use of the STL.
For each type FOO in your module you provide a new_FOO which is called when you
create an object. There you can call any C++ code including class constructors.
PyCXX helps you in filling out these long structs needed for a new type.
It helps with exception handling and reference counting.
I am new to PyCXX myself, but it worked very soon. There is a rather general
example in the Demo directory. I've just copied and modified the code and it
worked like expected - GREAT! The documentation is not too long but suffucient
and very readable. It does NOT (try to) wrap your C++ classes automatically like
other tools. I prefer this (since I don't have hundreds of classes). One can
easily fully understand what's going on and if something is missing (e.g. I think
conversion of an unsigned int to a Python long int) one can easily add this
feature using calls from the C-API himself.
--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
Jul 18 '05 #9
Neal D. Becker wrote:
Helmut Jarausch wrote:

Francois Fernandes wrote:
Hi!

Is it possible to easyly integrate c++ classes in python?

I don't want to use boost c++.

Does anyone know how to start or where to find documentation for this?


I prefer PyCXX http://cxx.sourceforge.net

Looks interesting. I want to expose lots of signal processing algorithms
written in C++ to python. I want to use std::vector for containers,
because they are fast. I need to create python types for
std::vector<dou ble> and std::vector<std ::complex<doubl e>> at minimum. The
Python interface doesn't need to know much about these types, just be able
to create vectors of a given size.

Would PyCXX be a good choice for this? Are there any samples of code
similar to this?


I think, yes. PyCXX allows for use of the STL.
For each type FOO in your module you provide a new_FOO which is called when you
create an object. There you can call any C++ code including class constructors.
PyCXX helps you in filling out these long structs needed for a new type.
It helps with exception handling and reference counting.
I am new to PyCXX myself, but it worked very soon. There is a rather general
example in the Demo directory. I've just copied and modified the code and it
worked like expected - GREAT! The documentation is not too long but suffucient
and very readable. It does NOT (try to) wrap your C++ classes automatically like
other tools. I prefer this (since I don't have hundreds of classes). One can
easily fully understand what's going on and if something is missing (e.g. I think
conversion of an unsigned int to a Python long int) one can easily add this
feature using calls from the C-API himself.
--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany

Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
10219
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9998
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3967
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 we have to send another system
2
3567
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.